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

How do I Reset Player Stats on Death?

Hello, I'm fairly new to scripting and I'm having troubles figuring out how to change values (Gold, Lvl, XP, STR, DEX, ect..) when the character dies. I've tried to write it different ways, and even used a few scripts I found online with no luck. Could some please help me? Thank You!

I'm guessing I should create a Function that resets all stats to the default, and have it trigger on death?

1 comment

0

Provide us the script what u were trying to do because im 99% sure you didn't do anything nor try.

1 answer

I'm assuming you want to set the player's values to 0, otherwise be more specific.

game.Players.PlayerAdded:connect(function(player)
	
	-- sets up the leaderstats when the player joins the server
	local leaderstats = Instance.new("Model", player)
	leaderstats.Name = "leaderstats"
	local Gold = Instance.new("IntValue", leaderstats)
	Gold.Name = "Gold"
	Gold.Value = 200 -- just an example
	local Level = Instance.new("IntValue", leaderstats)
	Level.Name = "Level"
	Level.Value = 200 -- just an example
	local XP = Instance.new("IntValue", leaderstats)
	XP.Name = "XP"
	XP.Value = 200 -- just an example; you can add more
	
	player.CharacterAdded:connect(function(character)
		local humanoid = character:FindFirstChild("Humanoid")
		if humanoid then
			humanoid.Died:connect(function() -- connects the humanoid died function
				-- resets values
				Gold.Value = 0
				Level.Value = 0
				XP.Value = 0
			end)
		end
	end)
end)

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