I have a GUI for an Obby Game that shows up every death as a help popup, but I want it to appear every 3 deaths instead of 1. How would I do this?
Here’s my current code:
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
script.Parent.Enabled = true
end)
Make a variable that holds how many deaths a player has. Every time the player dies, add 1 to the variable and then add an if statement checking whether the player has reached 3 deaths then add the popup and reset the variable to 0 deaths.
I’m assuming the GUI is in a ScreenGui with ResetOnSpawn set to true. Set ResetOnSpawn to false, and keep track of deaths using a variable.
Code:
--//Services
local Players = game:GetService("Players")
--//Variables
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
--//Controls
local deaths = 0
--//Functions
local function OnCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Once(function()
deaths += 1
if deaths == 3 then
deaths = 0
script.Parent.Enabled = true
end
end)
end
player.CharacterAdded:Connect(OnCharacterAdded)
OnCharacterAdded(character)