So basically I made a thing where I add the player's WalkSpeed whenever he touches it and after 2 seconds it should go off. but what I found is that it ran for over 30 seconds. then I printed the new value. What I found is that it goes up for no reason! I have 3 scripts to work with those the values. Here they are. But what's the issue what the value going up and down?
One that reduce the value:
game:GetService("RunService").Heartbeat:connect(function() local x = 1/workspace:GetRealPhysicsFPS() print(x,y) if y.Value > 0 then y.Value = y.Value - x else y.Value = 0 -- set to zero so it doesnt go beyond (-.1/60)-infinitely small number end end)
another one that set the value:
script.Parent.Touched:Connect(function(part) if part.Name == 'RightFoot' then local plr = part.Parent if game.Players:FindFirstChild(plr.Name) then local Folder = game:GetService'ReplicatedStorage'[plr.Name] if Folder:WaitForChild'canRefreshSprintingTimeLeft'.Value == true then setVal(Folder:WaitForChild'canRefreshSprintingTimeLeft',false) game:GetService'Players'[plr.Name]:WaitForChild'sprintingTimeLeft'.Value = 2 print'added' wait(1) setVal(Folder:WaitForChild'canRefreshSprintingTimeLeft',true) end end end end)
and the one that adds the WalkSpeed:
localPlayer:WaitForChild'sprintingTimeLeft'.Changed:Connect(function(newVal) if newVal > 0 then local Hu = workspace[localPlayer.Name]:WaitForChild'Humanoid' repeat wait(.15) local y = Hu.WalkSpeed + Folder:WaitForChild'additiveSpeed'.Value*.2 Hu.WalkSpeed = y until Hu.WalkSpeed > 30+(Folder:WaitForChild'maximumSpeed'.Value*6) or newVal <= 0 Hu.WalkSpeed = 35 end end)
about the outputs: added is printed once only; x is always .016666666666666666... (1/60)(at least after I touched the thing) and the y(time left) is going up and down