Hi, I am making a treadmill for my weight lifting simulator, but the loop never stops when I step off the treadmill. I've tried to make a true or false statement but it did not work. Anybody have a possible solution?
local character = game.Players.LocalPlayer.Character.Humanoid local speed = game.ReplicatedStorage.Speed function onTouched(hit) while true do speed.Value = speed.Value + 10 wait(1) speed.Value = speed.Value + 10 wait(1) end end script.Parent.Touched:connect(onTouched) if character = nil then return end
Re-write your script with mine and what it will do is when you step off the treadmill the loop will stop.
local character = game.Players.LocalPlayer.Character.Humanoid local speed = game.ReplicatedStorage.Speed local db = true function stop() db = false wait(2) db = true end function onTouched(hit) while true do speed.Value = speed.Value + 10 if db == false then break end wait(1) speed.Value = speed.Value + 10 if db == false then break end wait(1) if db == false then break end end end script.Parent.Touched:connect(onTouched) script.Parent.TouchEnded:Connect(stop) if character = nil then return end
I hope that helps :D