I have a toll booth script, and upon touching, the player should loose 12 money, but it doesn't work for some reason.

script.parent.OpenHitbox.Touched:Connect(function(hit)
	if debounce == false then 
		debounce = true
		print("Player")
		local check = hit.Parent:FindFirstChild("Humanoid")
		local user = game.Players:GetPlayerFromCharacter(hit.Parent) --get player from touching human
		local stats = user:FindFirstChild("Leaderstats")
		local cash = stats:FindFirstChild("Money")
		if check ~= nil then
			if stats ~= nil then
				cash.Value = cash.Value -10
				print("Removed $10 from player")
				open()
				print("Gate Opened")
				wait(4)
				close()
				print("Gate Closed")
			end
		end
	end
end)

instead I get a nil error

3 comments

0

is cash a NumberValue/IntValue?

0

which line gives the error?

0

Line 9 gives a nil error