How to lose a life when you die

I will try yours now.

I hope it works

1 Like

This script didn’t work either.

I’m really confused now

Can you give us an screenshot of the explorer?

1 Like

This is the screenshot

An ) is missing at the end, consider putting one there.

image

https://developer.roblox.com/en-us/api-reference/event/Humanoid/Died/index.html

1 Like

I added the ), and it still is unable to change.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			player.leaderstats.Lives.Value = player.leaderstats.Lives.Value - 1
		end)
	end)
end)

This may be it.

1 Like

Yet again, the lives remained the same.

1 Like

Can you show us the leaderstats script? I think it’s the PlayerSetup.

2 Likes

function setup(player)

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

	local lives = Instance.new("IntValue")
lives.Name = "Lives"
lives.Parent = leaderstats
lives.Value = 5

local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Parent = leaderstats
coins.Value = 0

local level = Instance.new("IntValue")
level.Name = "Level"
level.Parent = leaderstats
level.Value = 1

player.RespawnLocation = workspace.level1.level1Spawn

end

game.Players.PlayerAdded:Connect(setup)

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			player:WaitForChild("leaderstats").Lives.Value = player.leaderstats.Lives.Value - 1
		end)
	end)
end)

1 Like

nope :frowning:

I think this is expected to not work, change the leaderstats script to this:

game.Players.PlayerAdded:Connect(function(player)

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

	local lives = Instance.new("IntValue")
lives.Name = "Lives"
lives.Parent = leaderstats
lives.Value = 5

local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Parent = leaderstats
coins.Value = 0

local level = Instance.new("IntValue")
level.Name = "Level"
level.Parent = leaderstats
level.Value = 1

player.RespawnLocation = workspace.level1.level1Spawn
end

After that, try again.(Dont change the died script!)

1 Like

that completely broke the game lol. All the leaderstats disappeared and I spawned in level 11

game.Players.PlayerAdded:Connect(function(plr)
wait(2)
local hum = plr.Character:WaitForChild("Humanoid")
 hum.Died:connect(function()
 local leaderstats = plr:FindFirstChild("leaderstats")
 local stat = leaderstats:FindFirstChild("Lives") 
 stat.Value = stat.Value -1
 end)
 end)

Use this in a normal script inside the server script service and it should work.

1 Like

You are a hero my sir! It finally worked.

2 Likes

Yes!!! Finally!

[30 charssssss]

1 Like

Never mind :frowning:

It only worked for one death, every death after that the number remained

game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:connect(function()
local hum = plr.Character:WaitForChild("Humanoid")
 hum.Died:connect(function()
 local leaderstats = plr:FindFirstChild("leaderstats")
 local stat = leaderstats:FindFirstChild("Lives") 
 stat.Value = stat.Value -1
 end)
 end)
end)

Try this?

2 Likes

It worked this time! thank you

2 Likes