#one of my guns reload every gun in the backpack can any1 help

1 messages · Page 1 of 1 (latest)

upbeat canyon
#

This is the server sided code for reloading:

local function reload(player)
task.spawn(function()
task.wait(0.1)
ReloadSound:Play()
end)
task.spawn(function()
AllowedToShoot.Value = false
task.wait(1.7)
AllowedToShoot.Value = true
end)

local maxAmmo = tool:GetAttribute("MaxAmmoInGun")
local neededAmmo = maxAmmo - ReadyToShoot.Value

if AmmoInGun.Value > 0 and neededAmmo > 0 then
    if AmmoInGun.Value >= neededAmmo then
        AmmoInGun.Value -= neededAmmo
        ReadyToShoot.Value += neededAmmo
    else
        ReadyToShoot.Value += AmmoInGun.Value
        AmmoInGun.Value = 0
    end
end

print("Ready to shoot: " .. ReadyToShoot.Value)
print("Ammo In Gun: " .. AmmoInGun.Value)

end

kindred haloBOT
#

studio** You are now Level 3! **studio

upbeat canyon
#

this is the client sided one:

local tool = script.Parent
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:FindFirstChild("Humanoid")
local mouse = plr:GetMouse()
local fireevent = tool:WaitForChild("Shoot")
local UIS = game:GetService("UserInputService")
local ReloadingAnim = script.Reloading
local reloadevent = tool.Reload
local idleANIM = script.GunIDLE
local Equipping = script.Equipping
local Track1
local GunIDLE
local Reloading
local reloadDebounce = false
local debounce = false
local clientsideddebounce = false

local ReadyToShoot = tool.ReadyToShoot
local AmmoInGun = tool.AmmoInGun

UIS.InputBegan:Connect(function(input,busy)
if not busy then
if input.KeyCode == Enum.KeyCode.R then
if AmmoInGun.Value > 0 and ReadyToShoot.Value < 20 then
if not reloadDebounce then
reloadDebounce = true
local MagClone = tool.Handle.Mag:Clone()
MagClone.Parent = workspace
MagClone.CFrame = tool.Handle.Mag.CFrame
MagClone.CanCollide = true
task.spawn(function()
task.wait(6)
MagClone:Destroy()
end)
Reloading = hum:LoadAnimation(ReloadingAnim)
Reloading:Play()
Reloading:AdjustSpeed(1)
reloadevent:FireServer()
print("reloaded 1")
Reloading.Stopped:Wait()
reloadDebounce = false
end
end
end
end
end)

twilit fossil
#

you are connecting to uis more than once hehe it's not one of your guns, it's all of them hehe

upbeat canyon
#

wym

upbeat canyon
#

ik its all of them but idk how to fix it

twilit fossil
# upbeat canyon wym

local tool = script.Parent (it's a script that is duplicated for every tool)
UIS.InputBegan:Connect(function(input,busy) (each duplicate connects to this event presumably)

twilit fossil
upbeat canyon
#

how to i fix it then

#

imma send u the layout

twilit fossil
#

this aint a simple thing to fix

upbeat canyon
twilit fossil
#

it's not a change one line thing, it's a move the entire block somewhere else that only connects once

twilit fossil
upbeat canyon
#

LOL

#

u got me ngl

#

i used it for like 1 part

twilit fossil
gentle kelp
#

Use Tool.Equipped and Tool.Unequipped events to determine which weapon is equipped so that the UserInputService doesn't interfere with inactive guns

upbeat canyon
#

what should I do then

twilit fossil
#

i think a funny cheap hack to make that work is just if not tool.Parent==char then return end

gentle kelp
#

yeah true...

twilit fossil
#

100% Certified EfFiCiEnCt AnD oPtImIzEd