I'm trying to script a money giver that disappears after it's been used. and then comes back after 200 seconds. It is a part and I have the script within it.

It doesn't seem to work, anybody know why? Is it maybe my debounce code? Thanks in advance.

local pat = script.Parent
local done = 2

script.Parent.Touched:connect(function(pat)
	if done == 2 then
		local done = 1
	
	local player = game.Players:GetPlayerFromCharacter(pat.Parent)
	if player ~= nil then
		if script.Parent.Owner.Value == player then
			if pat.Parent:FindFirstChild("Humanoid") then
				if pat.Parent.Humanoid.Health > 0 then
					local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
					if cashmoney ~= nil then 
						cashmoney.Value = cashmoney.Value + (10000) --give money
						wait (1)
						script.parent:MoveTo(Vector3.new (423, 141, 512)) 
					--moves thing to undisclosed location
						wait (200)
						script.parent:MoveTo(Vector3.new(548.7, 313, -251.5))
					--back to original location
						if done == 1 then 
							local done = 2  --debounce complete
						
					end
				end
			end
		end
	end
	end
end
end)


2 comments

0

Remove the locales from lines 6, and 24. This creates a new local variable rather than reassigning the local declared on line 2. DON'T remove the local on line 2

0

wow, didnt know local things worked like that, thanks