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

How can I make the message appear once only?

Asked by 6 years ago
Edited 6 years ago

I'm currently learning functions. I don't know how I can make the message appear once only.

function PartTouch()
m = Instance.new("Message", game.Workspace)
m.Text = "Ouch! That hurts!"
wait(5)
m:Remove()
end
game.Workspace.Part.Touched:connect(PartTouch)

1 answer

Log in to vote
0
Answered by 6 years ago

Try adding a debounce! (code below)

debounce = false

function PartTouch()
 if debounce = false then
   debounce = true
m = Instance.new("Message", game.Workspace)
m.Text = "Ouch! That hurts!"
wait(5)
m:Remove()
wait(3)
debounce = false
 end
end

game.Workspace.Part.Touched:connect(PartTouch)

Ad

Answer this question