Code unable to add to a number value

Hello, I made a cash system and I want to give the cash to the player when they touch a part but for some reason it doesn’t work.
Here is my program:

script.Parent.Transparency = 1

local function GiveCash(plr)
	plr.Cash.Value = plr.Cash.Value + 10
end

script.Parent.Touched:Connect(function(hit)
	script.Parent.CanTouch = false
	script.Parent.Collect:Play()
	script.Parent.Pop:Play()
	script.Parent.BillboardGui.Enabled = false
	GiveCash()
	wait(5)
	script.Parent.BillboardGui.Enabled = true
	script.Parent.CanTouch = true
end)

!!ANY HELP IS AMAZING!!

Your function (GiveCash) requires an argument.
Also, use task.wait() instead of wait.

To get the player from the hit:

local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)

And then you’ll need to call your function:

GiveCash(Player)

You forgot to add the player

Copy this code:

script.Parent.Transparency = 1

local function GiveCash(plr)
	plr.Cash.Value = plr.Cash.Value + 10
end

script.Parent.Touched:Connect(function(hit)
 if hit.Parent:FindFirstChild("Humanoid") then
	script.Parent.CanTouch = false
	script.Parent.Collect:Play()
	script.Parent.Pop:Play()
	script.Parent.BillboardGui.Enabled = false
   local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	GiveCash(Player)
	wait(5)
	script.Parent.BillboardGui.Enabled = true
	script.Parent.CanTouch = true
 end
end)

dude omg tysm you helped me so much <3

1 Like

You guys are awesome! Thanks so much!

1 Like