01 | if randomPlayer.Character:WaitForChild( "Humanoid" ).Died then |
02 | for i,v in pairs (Game.Players:GetPlayers()) do |
03 | pcall ( function () |
04 | v.PlayerGui.TopFrameENDED.TextButton.TextTransparency = 0 |
05 | v.PlayerGui.TopFrame.TextButton.TextTransparency = 1 |
06 | wait( 2 ) |
07 | v.PlayerGui.TopFrameENDED.TextButton.TextTransparency = 1 |
08 | v.PlayerGui.TopFrame.Main.Disabled = true |
09 | wait( 0.03 ) |
10 | v.PlayerGui.TopFrame.Main.Disabled = false |
11 | v.PlayerGui.TopFrame.TextButton.TextTransparency = 0 |
12 | 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:
01 | randomPlayer.Character:WaitForChild( "Humanoid" ).Died:connect( function () |
02 | for i,v in pairs (Game.Players:GetPlayers()) do |
03 | pcall ( function () |
04 | v.PlayerGui.TopFrameENDED.TextButton.TextTransparency = 0 |
05 | v.PlayerGui.TopFrame.TextButton.TextTransparency = 1 |
06 | wait( 2 ) |
07 | v.PlayerGui.TopFrameENDED.TextButton.TextTransparency = 1 |
08 | v.PlayerGui.TopFrame.Main.Disabled = true |
09 | wait( 0.03 ) |
10 | v.PlayerGui.TopFrame.Main.Disabled = false |
11 | v.PlayerGui.TopFrame.TextButton.TextTransparency = 0 |
12 | end ) |
13 | end ) |
Well you could restart the whole thing, make it so that the died funtion comes first
like
01 | function Died() |
02 | for i,v in pairs (Game.Players:GetPlayers()) do |
03 | pcall ( function () |
04 | v.PlayerGui.TopFrameENDED.TextButton.TextTransparency = 0 |
05 | v.PlayerGui.TopFrame.TextButton.TextTransparency = 1 |
06 | wait( 2 ) |
07 | v.PlayerGui.TopFrameENDED.TextButton.TextTransparency = 1 |
08 | v. PlayerGui. TopFrame. Main. Disabled = true |
09 | wait( 0.03 ) |
10 | v.PlayerGui.TopFrame.Main.Disabled = false |
11 | v.PlayerGui.TopFrame.TextButton.TextTransparency = 0 |
12 | end ) -- not sure if you need this ) if it dosen't work remove that |
13 | end |
14 |
15 | 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)