I'm trying to make it so that the print will count up by 1 point/bValue per second only while walking, but my script's while loop never breaks for some reason, so it works for the most part, it just doesn't stop counting when the player stops walking.
-- local bValue = script.Parent.Parent.Parent.StarterGui.ScreenGui.TextButton.bValue (code for later)
local bValue = 0
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
humanoid.Running:Connect(function(speed)
while speed >= 16 do
wait(1)
-- bValue.Value = bValue.Value + 1 (also for later)
bValue = bValue + 1
--print(bValue.Value)
print("bValue is: " .. bValue)
print("Speed is: " .. speed)
if speed < 16 then
break
end
end
end)

12 comments
So I implemented debounce, and removed the while loop, the code now runs once when I start walking, but doesn't add 1 point/sec while walking, and after 3 points added the script broke all together, also the wait has to go first as to stop people from spamming w to get points quicker
Update: fixed the script breaking issue, but now the 2nd if statement that's meant to check if the player is still walking after 1 second doesn't work as intended, and the 1point/sec still doesn't work while continuously walking.
@SpelunkyGaming Oh, I forgot! When the player walks, the speed will mostly be maintained. I'll put a new fix in the answer.
ok! thank you, btw! I'm pretty new to scripting and things like this are a huge help.
@SpelunkyGaming (is tagging this way works) I edited my post! Hope that works well on both you and your game, I'm currently on mobile rn haha so I'm sorry it may go out faulty since it's untested. Gimme a knock if it does or does nuh!
@SpelunkyGaming edited again... some minor fixes. with explanations
I'm afraid pinging doesn't do much (It'd be cool if it did though), however I'm working with the comments and resources you gave me, and I'm testing a bunch f things now, this is extremely helpful! Especially since I've heard terms like DeltaTime before but didn't quite know what it was.
Simply speaking, delta time is like time difference: timePresent - timePast = deltaTime. Delta generally means difference in variables in mathematics as I've learnt, etc. delta also stands for the triangle letter thing uknow greek stuff
Anyways I wish you goodluck on whatever you're doing rn!
Again, thank you so much for helping me get this fixed, and thanks for the good luck, I'm sure I'll need it lol. Other than that the TextLabel GUI is being annoying but It's probably a simple fix... probably
No problem! Hmm, are you trying to get the gui in StarterGui instead of PlayerGui? StarterGui's children will be parented to the player's PlayerGui upon joining, which you'll have to use Player.PlayerGui for the result to be visible
well the script correctly sets the text in the properties tab, but it doesn't change the text in the actual game preview