I have been editing these guns for a while now, after picking them up off a free model and making them work to my liking, and I have an issue where I can only reload the first gun that loads into the game, when I attempt to reload another gun it just does nothing.
Is anything being thrown into the output? errors? warns? What about adding prints? That will help you see what is running and what isn’t running. This should be where you start.
One thing that stands out to me is you are setting Ammo.Value to string and then after that you are applying numbers to it and doing math. If its a Value object its either a Number or a string (or the other value objects in other cases.). Take a look at that as that will error on you.
local function reload()
print("hello this works")
reloadRemote:FireServer()
wait()
if canReload and relDeb == false and script.Parent.Parent.Configs.Reload.Value == true then
relDeb = true
reloadTrack:Play()
wait(.01)
reloadRemote:FireServer()
wait(2)
relDeb = false
end
end
Prints as soon as I press test, not equipped or R pressed. This is in the Local Script.
Are you saying its not running the “equipped” and “reload” functions? Trying to understand the script is a little difficult, what are the “Canshoot” and “Canreload” variables pointing to? They are in a folder called remotes, are they Remote event objects? Value Objects? Make sure the entire script is loading by putting a print at the bottom. If that prints then you can know that there was no error when the script first initializes. Then go ahead and add a print to each function/event you want to test. See which ones run and which ones do not.
From the looks of it things appear to be setup sort of odd, for example setting the equipped variable to true but not actually checking in the functions if it is equipped or not. When someone presses “R” in that script the first thing you should be doing is checking to make sure the gun is equipped before firing the remote. What if you have two guns? Will the remote fire twice when you press R since both events are still being listened for? That being said, start by adding prints in key points in the script like i suggested. You only sent a small snippet so i don’t know where you added them in your last reply.
It’s only the Reloading that doesn’t work ON EVERY GUN BUT ONE (probably the first that loads in).
The print I placed in the snippet above printed as soon as I entered the game, instead of when I pressed R, or even equipped the gun. The scripts seems to be running fine, and the BackendScript makes sure that the gun is allowed to reload.
Okay, thanks for clarifying. If those are remote functions and you are looking to check something such as shooting and reloading you would want to use RemoteFunction:InvokeServer(), However, i would not recommend doing this as it will cause extreme latency when using the weapon so those checks are almost redundant amongst other things that could cause it to act strange. Do you have a model that i can look at to test in my own studio?
Unbind the actions in the Unequipped event function, but also have the actions binded in the Equipped event function.
local function unequip()
equipped = false
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
sprinting = false
humanoid.WalkSpeed = 16
mouse.Icon = oldIcon
if holdTrack then
holdTrack:Stop()
end
if sprintTrack then
sprintTrack:Stop()
end
actionService:UnbindAction("Reload")
actionService:UnbindAction("Sprint")
end
When scripting things such as guns and using ContextActionService, always unbind the actions on unequip and bind them on equip.