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

Why is this running instantly?

Asked by
iLegitus 130
10 years ago
if  randomPlayer.Character:WaitForChild("Humanoid").Died then
    for i,v in pairs(Game.Players:GetPlayers()) do 
    pcall(function() 
    v.PlayerGui.TopFrameENDED.TextButton.TextTransparency = 0
    v.PlayerGui.TopFrame.TextButton.TextTransparency = 1
    wait(2)
    v.PlayerGui.TopFrameENDED.TextButton.TextTransparency = 1
    v.PlayerGui.TopFrame.Main.Disabled = true
    wait(0.03)
    v.PlayerGui.TopFrame.Main.Disabled = false
    v.PlayerGui.TopFrame.TextButton.TextTransparency = 0
    end)

That is found inside a function,And yes "randomPlayer" is recognized,I made it chose one random player out of a server.

I just want this to be able to run WHENEVER the randomPlayer dies,But whenever the function is ran,It runs instantly.

Help,Greatly appriciated.

2 answers

Log in to vote
3
Answered by
gskw 1046 Moderation Voter
10 years ago

Died is an event, not a property. As it exists and is an event, it will always evaluate to true. This is the correct way to use events:

randomPlayer.Character:WaitForChild("Humanoid").Died:connect(function()
    for i,v in pairs(Game.Players:GetPlayers()) do 
        pcall(function() 
            v.PlayerGui.TopFrameENDED.TextButton.TextTransparency = 0
            v.PlayerGui.TopFrame.TextButton.TextTransparency = 1
            wait(2)
            v.PlayerGui.TopFrameENDED.TextButton.TextTransparency = 1
            v.PlayerGui.TopFrame.Main.Disabled = true
        wait(0.03)
       v.PlayerGui.TopFrame.Main.Disabled = false
        v.PlayerGui.TopFrame.TextButton.TextTransparency = 0
    end)
end)
Ad
Log in to vote
0
Answered by
Azenix 1
10 years ago

Well you could restart the whole thing, make it so that the died funtion comes first

like

function Died()
for i,v in pairs(Game.Players:GetPlayers()) do
        pcall(function()
            v.PlayerGui.TopFrameENDED.TextButton.TextTransparency = 0
            v.PlayerGui.TopFrame.TextButton.TextTransparency = 1
            wait(2)
            v.PlayerGui.TopFrameENDED.TextButton.TextTransparency = 1
            v. PlayerGui. TopFrame. Main. Disabled = true
        wait(0.03)
       v.PlayerGui.TopFrame.Main.Disabled = false
        v.PlayerGui.TopFrame.TextButton.TextTransparency = 0
    end) -- not sure if you need this ) if it dosen't work remove that
end

randomPlayer.Character:WaitForChild("Humanoid").Died:connect(Died)

Idk if this will work but i think it might here is text again so you can copy without coping numbers: function Died() for i,v in pairs(Game.Players:GetPlayers()) do pcall(function() v.PlayerGui.TopFrameENDED.TextButton.TextTransparency = 0 v.PlayerGui.TopFrame.TextButton.TextTransparency = 1 wait(2) v.PlayerGui.TopFrameENDED.TextButton.TextTransparency = 1 v. PlayerGui. TopFrame. Main. Disabled = true wait(0.03)  v.PlayerGui.TopFrame.Main.Disabled = false v.PlayerGui.TopFrame.TextButton.TextTransparency = 0 end) -- not sure if you need this ) if it dosen't work remove that end

randomPlayer.Character:WaitForChild("Humanoid").Died:connect(Died)

Answer this question