Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How can I make this only print once?

Asked by 8 years ago
local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char.Humanoid

hum.Running:connect(function(speed)
    if speed > 0 then
    print(" I'm walking ")
    else
    print("I stopped walking")
    end
end)

How can I make this print once? So when he starts walking it only prints it once? and not repeatly and infinitely? And when he stops he only prints the "I stopped walking" once?

0
Does the speed change if you stop walking the walk speed of the humanoid... I don't think that the walk speed of the humanoid changes... What is the argument of speed? KingLoneCat 2642 — 8y

3 answers

Log in to vote
0
Answered by 8 years ago

This is simple I included debouncers and alot more aswell.

local plr = game.Players.LocalPlayer

local char = plr.Character

local hum = char.Humanoid

local prin = true
local deb = true

hum.Running:connect(function(speed)
    if speed > 0 then
    if prin and deb then
    deb, prin = false
    print("Walken")

wait(0.2)
deb = true
end
elseif not prin and deb then
    deb, prin = false, true
print("Stopped")
wait(0.2)
deb = true

    end
end)

0
Why do you make a double debounce? iDarkGames 483 — 8y
0
one is so they have to wait a specific time before being able to do it again. and another is to show that we have allready ran and we are waiting for the person not to be running. e.e. Angels_Develop 52 — 8y
Ad
Log in to vote
1
Answered by 8 years ago

I think it isn't possible. Maybe use debounce?

0
You're right but the way he would have to use the debounce would be a little different in order to allow the script to detect when the speed is also 0. Maybe two denounces... User#11440 120 — 8y
1
Yeah, maybe. I am really bad in lua actually. My lua is really basic. kaspar1230 345 — 8y
Log in to vote
0
Answered by
Hasburo 150
8 years ago
local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char.Humanoid
local print = false


hum.Running:connect(function(speed)
    if speed > 0 then
    if not print then
    print = true
    print(" I'm walking ")
    else
    print("I stopped walking")
    print= false
    end
end)

This is a situation where debounce comes in hand. It's intended for situations like this where the output is flooded with spam.

For more information, refer here.

Answer this question