So I am making a game sorta like bear, whereas when a player gets hurt, gui pops up on the screen like this. But it loops, and I don’t know why, here is the video + script.
It loops whenever I get hurt while the hurt GUI (idk what its called) is playing, here is the script:
workspace[game.Players.LocalPlayer.Name]:WaitForChild("Humanoid")
label = script.Parent.TextLabel
debounce = true
local function hurt()
if debounce == true then
debounce = false
local num = math.random(1,3)
if num == 1 then
label.Text = "BEHIND YOU"
elseif num == 2 then
label.Text = "RUN"
elseif num == 3 then
label.Text = "ITS HERE"
end
script.Parent.LocalScript.Disabled = false
local num = 0
while wait(.01) do
local clone = game.ReplicatedStorage.special:Clone()
clone.Parent=script.Parent
num = num + .01
if num >= .75 then
script.Parent.TextLabel.Text = ""
break
end
end
debounce = true
end
end
workspace[game.Players.LocalPlayer.Name].Humanoid:GetPropertyChangedSignal('Health'):Connect(hurt)
Try making it so it waits a little before activating the debounce:
workspace[game.Players.LocalPlayer.Name]:WaitForChild("Humanoid")
label = script.Parent.TextLabel
debounce = true
local function hurt()
if debounce == true then
debounce = false
local num = math.random(1,3)
if num == 1 then
label.Text = "BEHIND YOU"
elseif num == 2 then
label.Text = "RUN"
elseif num == 3 then
label.Text = "ITS HERE"
end
script.Parent.LocalScript.Disabled = false
local num = 0
while wait(.01) do
local clone = game.ReplicatedStorage.special:Clone()
clone.Parent=script.Parent
num = num + .01
if num >= .75 then
script.Parent.TextLabel.Text = ""
break
end
end
wait(1)
debounce = true
end
end
workspace[game.Players.LocalPlayer.Name].Humanoid:GetPropertyChangedSignal('Health'):Connect(hurt)
still does the same thing execpt it waits a second (Ive set it like that) to do the next one, so still loops, only slower
edit: I had a wait on there before, but it looks like I deleted it. not sure why, but I probably deleted it when I moved a function that was above the main code to inside of it.
so it looks like what i set the wait for the debounce to come back on (?) is the wait for the loop to start again, so for example if I set it for 4 seconds, it would:
do it once, wait four second, then do it again, rinse and repeat approx. 6 times