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

How do I make it so every 5 times a player has died, a GUI pops up?

Asked by 4 years ago

How do I make it so every 5 times a player has died, a GUI pops up?

0
i am confused, do you have a script at all that isent working? Kaput_0 44 — 4y
0
No, i just want to make so every time a player died, a GUI will show up when they respawn, YelloMynamesZak 85 — 4y

1 answer

Log in to vote
0
Answered by
Grazer022 128
4 years ago
Edited 4 years ago

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

  • Grazer022
0
if this solves your problem, remember to make it the answer. Thanks! Grazer022 128 — 4y
0
Line 9 and 11 are wrong. You will need to get the GUI's from the player's PlayerGui instead of the StarterGui for the player to actually see any changes you make to the Guis'. xInfinityBear 1777 — 4y
0
ah yes. That is correct, im gonna edit that Grazer022 128 — 4y
Ad

Answer this question