I have a problem with my snowball reload time. I have a numberValue in ReplicatedStorage preset to 5. When I buy a better fort, it makes my reload time go down as you can see in the video. The problem is that even though the numberValue goes down, the actual reload time doesn’t. I have it printing the value when I click and it stays at 5.
Here’s a section of the code where I call the variable for the first time. This is the part in the script that makes the snowball shoot:
MouseEvent.OnServerEvent:Connect(function (clientThatFired, mousePoint)
FIRE_DELAY = rs:WaitForChild("reloadSnowball").Value
print(FIRE_DELAY)
if not CanFire then
return
end
CanFire = false
local mouseDirection = (mousePoint - FirePointObject.WorldPosition).Unit
for i = 1, BULLETS_PER_SHOT do
Fire(mouseDirection)
end
if FIRE_DELAY > 0.03 then wait(FIRE_DELAY) end
CanFire = true
end)
In the script “FIRE_DELAY” is underlined in blue.
Here’s the GUI button that I clicked in the video:
local bought = false
local reps = game:GetService("ReplicatedStorage")
plrgoto = reps:WaitForChild("uigotoplr6")
script.Parent.MouseButton1Click:Connect(function()
if bought == false then
plrgoto:FireServer()
reps:WaitForChild("reloadSnowball").Value = 0.85
bought = true
end
end)
1 Like
Also when I change the value of the numberValue before I start the game, it sets itself to that. It just won’t reassign the value ingame.
You’re changing the value on the client and expecting the server to reflect the change. You should send the server the value through the remote if you intend on passing the information along.
1 Like
That’s usually because the variable’s a global variable and can/will be overwritten upon another execution of the code.
That’s because you’re changing the reload time from a LocalScript
- changes on the client aren’t replicated to the server. You’ll have to use another remote to be able to change the reload time, or handle the reload on the server all-together.
1 Like
umm… is this what you meant? Doing this still didn’t make it work XD
Gui button:
local bought = false
local reps = game:GetService("ReplicatedStorage")
plrgoto = reps:WaitForChild("uigotoplr2")
changereload = reps:WaitForChild("reload2")
script.Parent.MouseButton1Click:Connect(function()
if bought == false then
plrgoto:FireServer()
changereload:FireServer()
reps:WaitForChild("reloadSnowball").Value = 1.75
bought = true
end
end)
I made events for each button to change the numberValue… is there a faster and easier way of doing these kinds of things besides making a bunch of events?
I recommend having the server handle the reload time all-together, since the server handles the snowballs. You could check the type of weapon the player’s holding and upon execution have the reload time be based upon that. Assuming that this’s one main script handling all the snowballs
I just decided to make the reload time a global variable and change it in the server with the events called by the GUI buttons. Thanks for the help 
1 Like