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.
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)
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)