Hello, Im currently trying to make a simple Treadmill System where every 5 seconds on the treadmill, the players WalkSpeed increases by 0.02 (Currently 1 to see the speed change). Currently, my script is having a issue where it waits 5 seconds and then it gives the player the speed, HOWEVER, it starts giving the player +1 WalkSpeed Rapidly even Off the treadmill.
Script:
local part = script.Parent
part.Touched:Connect(function(hit)
while task.wait(5) do
local character = hit.Parent
if character then
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
humanoid.WalkSpeed += 1
end
end
end
end)
If you have a solution, please tell me, I’d love to know how to fix it!
local part = script.Parent
local debounceCharacters = {}
part.Touched:Connect(function(hit)
local character = hit.Parent
if character then
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
if debounceCharacters[character] then return end
debounceCharacters[character] = true
humanoid.WalkSpeed += 1
task.delay(5, function() debounceCharacters = false end)
end
end
end)
local part = script.Parent
local debounceCharacters = {}
part.Touched:Connect(function(hit)
local character = hit.Parent
if character then
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
if debounceCharacters[character] then return end
debounceCharacters[character] = true
humanoid.WalkSpeed += 1
task.delay(5, function() debounceCharacters[character] = false end)
end
end
end)
this works as intended, but is their a way to make it so it resets when the player goes off of the part? If not then ill label this script as the solution