IntValue inside of Player resets when the player dies

I have an IntValue inside of the player which is added through a script in ServerScriptService, it works, but whenever the player dies the IntValue goes back to 0, anyone know a fix?

Script in ServerScriptService:

game.Players.PlayerAdded:Connect(function(player)
	local PlayerStats = Instance.new("Folder", player)
	PlayerStats.Name = "PlayerStats"
	
	local Candy = Instance.new("IntValue", PlayerStats)
	Candy.Value = 250
	Candy.Name = "Candy"
	
	local QuestInfo = Instance.new("Folder", player)
	QuestInfo.Name = "QuestInfo"
	
	local BrainHunt = Instance.new("Folder", QuestInfo)
	BrainHunt.Name = "BrainHunt"
	
	local InProgress = Instance.new("BoolValue", BrainHunt)
	InProgress.Name = "InProgress"
	InProgress.Value = false
	
	local NumberOfBrains = Instance.new("IntValue", BrainHunt)
	NumberOfBrains.Name = "NumberOfBrains"
	NumberOfBrains.Value = 0
	
	local Completed = Instance.new("BoolValue", BrainHunt)
	Completed.Name = "Completed"
	Completed.Value = false
end)```

There’s nothing visibly wrong with this code, have you checked to see if you have anything running when the character dies or anything else resetting the values?

The problem ia when the player join it instances, You should make it when the character respawns.

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(Char) -- Fires when the player respawnes.
	local PlayerStats = Instance.new("Folder", player)
	PlayerStats.Name = "PlayerStats"
	
	local Candy = Instance.new("IntValue", PlayerStats)
	Candy.Value = 250
	Candy.Name = "Candy"
	
	local QuestInfo = Instance.new("Folder", player)
	QuestInfo.Name = "QuestInfo"
	
	local BrainHunt = Instance.new("Folder", QuestInfo)
	BrainHunt.Name = "BrainHunt"
	
	local InProgress = Instance.new("BoolValue", BrainHunt)
	InProgress.Name = "InProgress"
	InProgress.Value = false
	
	local NumberOfBrains = Instance.new("IntValue", BrainHunt)
	NumberOfBrains.Name = "NumberOfBrains"
	NumberOfBrains.Value = 0
	
	local Completed = Instance.new("BoolValue", BrainHunt)
	Completed.Name = "Completed"
	Completed.Value = false
end)
end)```
1 Like

But wouldn’t it still reset it because it’s still creating a new IntValue?

That’s the point, It will get back again :+1:

1 Like

Ah alright, but I need it to have the same value as before the player died.

Ohhhh, My bad xD

Try opening the script and press Ctrl + Shift + F.
Then search if aomething is setting it to 0

1 Like

Haha it’s fine, an IntValue is set to 0 by default so nothing is setting it to 0.

But the character is resetting, There is no reason for this to happen.

1 Like

Ty, I have no idea how to fix this :frowning: