How Do I Make My Gingerbread In This System Go Up When I Collect One

i have this system going.

how do i make it where the currency goes up after collecting a floating coin
i want to change this to gingerbread as well.
any help ?

1 Like
script.Parent.Touched:Connect(function(Object) -- Deecting if a object touch the "gingerbread"
	if Object.Parent:FindFirstChild("Humanoid") then -- Seeing if the object is a player
		game.Players[Object.Parent.Name].leaderstats.Gingerbread.value += 10 -- Set the value to anything you to give
	end
end)

That will make the coin give GingerBread.

game.Players.PlayerAdded:Connect(function(Player)
	local Folder = Instance.new("Folder")
	Folder.Parent = Player
	Folder.Name = "leaderstats"
	
	local InstanceCash = Instance.new('IntValue')
	InstanceCash.Name = "Cash" Change this into "Gingerbread"
	InstanceCash.Parent = Folder
	InstanceCash.Value = 1000
end)

Change the Cash Name into “Gingerbread” also you should change the value(InstanceCash) name to InstanceGingerbread, that should do it. Though in the feature try to make stuff like this system yourself. It much easier to work with cause you made it.

do i make a seperate script for the top one ?

yes, you’re going to want to put that inside the gingerbread script

some modifications you may want to consider

local Players = game:GetService("Players")

local function onTouched(hit)
	local model = hit:FindFirstAncestorWhichIsA("Model") -- looks for the model, which is the character
	if model then
		local humanoid = model:FindFirstChildWhichIsA("Humanoid")
		if humanoid and humanoid.Health > 0 then
			local player = Players:GetPlayerFromCharacter(model)
			if player then
				local leaderstats = player:FindFirstChild("leaderstats")
				if leaderstats then
					local gingerbreads = leaderstats:FindFirstChild("Gingerbreads")
					if gingerbreads then
						gingerbreads.Value += 1
					end
				end
			end
		end
	end
end

script.Parent.Touched:Connect(onTouched)

and for the other script:

local Players = game:GetService("Players")

local function playerAdded(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Player
	
	local Gingerbreads = Instance.new('IntValue')
	Gingerbreads.Name = "Gingerbreads"
	Gingerbreads.Value = 0
	Gingerbreads.Parent = leaderstats
end

for _, player in ipairs(Players:GetPlayers()) do
	coroutine.wrap(playerAdded)(player)
end

Players.PlayerAdded:Connect(playerAdded)

yes, you place it inside of the coin.