Speed Boost Help

Hello :smiley: , I have been trying to make Speed Boosts when players touch the parts they get a speed boost for 3 seconds and if they touch multiple they get more seconds of speed boost But whenever the speed boost runs out and try touching the part again it adds more than 3 on the time and the time doens’t go down per second

Any help would be incredibly helpful.


Server Script:

local collectionService = game:GetService("CollectionService")
local speed = 140

game.Players.PlayerAdded:Connect(function(player)
	local Time = player:WaitForChild("Timer")

	for _, parts in pairs(collectionService:GetTagged("SB")) do
		game.ReplicatedStorage.RE.SB:FireClient(player, parts)
		parts.Touched:Connect(function(hit)
			local locPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
			if player then
				parts.CanTouch = false
				parts.Transparency = 1 
				parts.Parent.G.Transparency = 1
				if locPlayer.Timer.Value > 0 then
					locPlayer.Timer.Value += 3
					game.ReplicatedStorage.RE.SBplayerSpeed:FireClient(locPlayer, speed)
				elseif locPlayer.Timer.Value == 0 then
					locPlayer.Timer.Value += 3
					game.ReplicatedStorage.RE.SBplayerSpeed:FireClient(locPlayer, speed)
					game.ReplicatedStorage.RE.YES:FireClient(player)
				end		
				
				wait(3)
				if locPlayer.Timer == 0 then
					locPlayer.Character.Humanoid.WalkSpeed = 100
				end
				parts.CanTouch = true
				parts.Transparency = 0
				parts.Parent.G.Transparency = 0
			end
		end)
	end
end)

Local Script:

local player = game.Players.LocalPlayer
local Time = player:WaitForChild("Timer")
local running = true
local RE = game.ReplicatedStorage.RE

RE.SBplayerSpeed.OnClientEvent:Connect(function(speed)
	if player.Character.Humanoid.WalkSpeed ~= 40 then
		print("PLAYER SPEED UPDATED TO 135 !!!!!!")
		player.Character.Humanoid.WalkSpeed = 40
	end	
end)

player:WaitForChild("Timer").Changed:Connect(function(timerVal)
	script.Parent.ScreenGui.SpeedTime.Text = timerVal
	if player.Timer.Value == 0 then
		player.Character.Humanoid.WalkSpeed = 16
	end
end)
local Time = game.Players.LocalPlayer:WaitForChild("Timer")

game.ReplicatedStorage.RE.YES.OnClientEvent:Connect(function()
	print("TRIGGERED ")
	while Time.Value > 0 do
		wait(1)
		if Time.Value > 0 then
			Time.Value -= 1
		end
	end

end)

Hello,
You’re setting the time value on the server, and subtracting it on the client.

Think of it like this, server updates the timer from 0 → 3, the client starts subtracting it to 0.
The client reads it as 0, the server still has 3, because it was just the client subtracting it,
The second time you collect it, it changes from 3 → 6 seconds.

Solution is subtracting the timer value on the server instead of the client.

1 Like

I love that explination! Thank you so much for the help ! :smiley:

1 Like