Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

2 comments

0

i am confused, do you have a script at all that isent working?

0

No, i just want to make so every time a player died, a GUI will show up when they respawn,

1 answer

✓ Accepted answer

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

3 comments

0

if this solves your problem, remember to make it the answer. Thanks!

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

0

ah yes. That is correct, im gonna edit that

This discussion is preserved as it was. New answers, comments, and votes are closed.