Somethings wrong with my value script

Hi,

So heres the script

local player = game.Players.LocalPlayer

player:WaitForChild("leaderstats").CreditsAmount.Changed:Connect(function(val)
	script.Parent.Text = "Credits: "..val
end)

script.Parent.Text = "Credits: "..player.PlayerStats:WaitForChild("CreditsAmount").Value

So when I kill a person it will add a certain amount of cash. This is just the script to show the amount. So when I kill a person I get a couple of credits(in this case). But when the other person kills me my credits go back down to 0. How do I make it so that my credits dont go down to 0 when I die.

The problem is with the text label script, not the kill to get credits script since the leaderstats stay the same.

From,
File

Does the label go back to normal when you respawn?

Is this right? I believe that PlayerStats should be leaderstats this would explain why it would be going down to 0, as whenever you die the GUI will reset and the leaderstats value isn’t being called when you’re changing the text

local player = game.Players.LocalPlayer
local creditStat = player:WaitForChild("PlayerStats"):WaitForChild("CreditsAmount")

creditStat.Changed:Connect(function(val)
	script.Parent.Text = "Credits: "..val
end)

script.Parent.Text = "Credits: "..player:WaitForChild("PlayerStats"):WaitForChild("CreditsAmount").Value

From what you’re talking about here, PlayerStats should still be leaderstats as if the credit value is stored in the leaderboard, the folder under the player has to be called leaderstats

I remember seeing their posts yesterday and they had named their leaderboard folder “PlayerStats”.

If you’re displaying a players data on the leaderboard, it has to go inside a leaderstats folder, the folder “PlayerStats” could have stored values that doesn’t display on the leaderboard, or they have a custom leaderboard or something.

You can read more here

Both of them know that, OP is literally using leaderstats in the same script. Player Stats is for player stats that won’t be displayed.

I know, I meant leaderboard, I think it’s custom.

it was originally leaderstats since I was testing if the value changed/ Then I changed it back because I know that I would work.

--Function call(Values)--
game.Players.PlayerAdded:Connect(function(player)
	--Folder--
	local PlayerStats = Instance.new("Folder") 
	PlayerStats.Name = "leaderstats"
	PlayerStats.Parent = player
	--Level amount--
	local LevelValue = Instance.new("NumberValue")
	LevelValue.Name = "LevelAmount"
	LevelValue.Parent = PlayerStats
	--Cash amount--
	local CreditsValue = Instance.new("NumberValue")
	CreditsValue.Name = "CreditsAmount"
	CreditsValue.Parent = PlayerStats
	
	player.CharacterAdded:Connect(function(Character)
		Character.Humanoid.Died:Connect(function(Died)
			local creator = Character.Humanoid:FindFirstChild("creator")
			local PlayerStats = creator.Value:FindFirstChild("leaderstats")
			if creator ~= nil and creator.Value ~= nil then
				PlayerStats.CreditsAmount.Value = PlayerStats.CreditsAmount.Value + 10
			end
		end)
	end)
end)

thats the credit script.

so to clear some air it used to be leaderstats. It was named that so I could see the value displayed. Then I changed ti back because I confirmed that it was working so there was no need for it to be used.