Currency system help

my script wont work can someone look over my script and tell me whats wrong

game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = Player

local cash = Instance.new("NumberValue")
cash.Name = "Cash"
cash.Value = 0
cash.Parent = leaderstats

Player.CharacterAdded:Connect(function(Charactor)
	Charactor.Humanoid.Died:Connect(function(Died)
		loaal creator = Charactor.Humanoid:FindFirstChild("creator")
		local leaderstats = creator.Value:FindFirstChild("leaderstats")
		if creator~= nil and creator.Value~= nil then
			leaderstats.Cash.Value = leaderstats.Cash + 10
		end
	end)
end)

end)

You just write loaal. Fix it to local.

And you need to add leaderstats to player when player joins.

alright i did that works now but when i kill a player it does not give 10 coins like its suppose to

Before even checking for a leaderstats variable, you should at least check that there is a creator value inside the Humanoid

game.Players.PlayerAdded:Connect(function(Player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = Player

    local cash = Instance.new("NumberValue")
    cash.Name = "Cash"
    cash.Value = 0
    cash.Parent = leaderstats

    Player.CharacterAdded:Connect(function(Charactor)
	    Charactor.Humanoid.Died:Connect(function(Died)
		    local creator = Charactor.Humanoid:FindFirstChild("creator")
		    if creator and creator.Value then
		        local leaderstats = creator.Value:WaitForChild("leaderstats")
			    leaderstats.Cash.Value = leaderstats.Cash.Value + 10
		    end
	    end)
    end)
end)

Also you misspelled local as “loaal”

i will try this thank you so much

i have errors

I hate when quotes are formatted like that

I edited it, try again

game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = Player

local cash = Instance.new("NumberValue")
cash.Name = "Cash"
cash.Value = 0
cash.Parent = leaderstats

Player.CharacterAdded:Connect(function(Charactor)
    local Humanoid = Charactor:WaitForChild("Humanoid")

	Humanoid.Died:Connect(function(Died)
	    local creator = Charactor.Humanoid:FindFirstChild("creator")

		if creator and creator.Value then
            local leaderstats = creator.Value.leaderstats
			leaderstats.Cash.Value += 10
		end
	end)
end)
end)

I will try that when I get back home thank you so much for helping

Try this:

game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder",player)
folder.Name = "leaderstats"
local currency1 = Instance.new("IntValue")
currency1.Name = "Money"
currency1.Parent = folder

player.CharacterAdded:Connect(function(character)
 character:WaitForChild("Humanoid").Died:Connect(function()
 local tag = character.Humanoid:FindFirstChild("creator")
if tag ~= nil then
   if tag.Value ~= nil then
	  currency1.Value = currency1.Value + 10 
			end 
		end
	end)
end) 
end)
1 Like

that worked thank you so much !!

Np! Anytime. Have a good scripting!

1 Like