Won't give the player cash

I’m trying to make a tycoon and I need a collector for it, but my script almost works, it doesn’t give the player cash when a drop is put in to the collector.

Script:

local players = game:GetService("Players")

local collecter = script.Parent

local basepart = collecter.BasePart

basepart.Touched:Connect(function(hit)
	if hit.Name == "Drop" then
		for _, player in ipairs(players:GetPlayers()) do
			player.leaderstats.Cash.Value += hit.CashValue.Value
		end
		hit:Destroy()
	end
end)

Do you get any errors from your console?

If your talking about the output, no, not sure what the console is

Another word for the output, have you attempted to place prints to ensure that the lines of code are actually running?

1 Like

try printing the hit.CashValue.Value and also printing for the touched event to make sure its getting called

Try this and see where it gets stuck

local players = game:GetService(“Players”)

local collecter = script.Parent

local basepart = collecter.BasePart

basepart.Touched:Connect(function(hit)
print(“basepart”)
if hit.Name == “Drop” then
print(“drop”)
for _, player in ipairs(players:GetPlayers()) do
print(player)
player.leaderstats.Cash.Value += hit.CashValue.Value
end
hit:Destroy()
end
end)

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.