How do I make it so every 5 times a player has died, a GUI pops up?
heya buddy! So you what you want to happen is when a player dies for 5 times a gui will show up right? In this explanation I will be using examples. Sit back and learn!
first of all we want to keep track of how many times a player died, so we do this!
game.Players.PlayerAdded:Connect(function(player) local death = Instance.new("IntValue", player) death.Name = "Death" end)
now what the code above does is we put an IntValue
on every player, an IntValue is a Value type that stores numbers, and we call the IntValue inside the player “Death”. Currently the value of Death
is 0. Now we want it to go up by one whenever the player dies.
game.Players.PlayerAdded:Connect(function(player) local death = Instance.new("IntValue",player) death.Name = "Death" player.CharacterAdded:Connect(function(character) local Humanoid = character:WaitForChild("Humanoid") end) end)
Okay now after line 3 we make a another event but this time it’s about the character, and what we need from the character is the humanoid which we can detect if they die.
game.Players.PlayerAdded:Connect(function(player) local death = Instance.new("IntValue",player) death.Name = "Death" player.CharacterAdded:Connect(function(character) local Humanoid = character:WaitForChild("Humanoid") Humanoid.Died:Connect(function() Death.Value = Death.Value + 1 end) end) end)
now we make another event that will run whenever the player dies. What that third event does is when the player dies, the value of Death
will go up by one. So if the player dies 3 times, the value would be 3 and if it’s let’s say 5, the value would be 5. Hence we continue
game.Players.PlayerAdded:Connect(function(player) local death = Instance.new("IntValue",player) death.Name = "Death" player.CharacterAdded:Connect(function(character) local Humanoid = character:WaitForChild("Humanoid") Humanoid.Died:Connect(function() Death.Value = Death.Value + 1 if Death.Value % 5 == 0 then game.PlayerGui.ScreenGui.YourGui.Visible = true else game.PlayerGui.ScreenGui.YourGui.Visible = false end end) end) end)
now we made an if statement checking if the value of Death is a multiple 5, if it is a multiple of 5 then your Gui that you want to be seen will be seen, else it won’t be seen at all.
Hope this helps and works!
NOTE: don’t copy the GUI in line 9 and 11, instead put the Gui names you want to be seen