Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Money button script for tycoon not working for some reason using can collide script?

I'm making a money giver that turns off and on to do this I'm using a simple can collide off and on but for some reason with this script in it. it will not give you the money here are the scripts.

while true do
wait(450)
	script.Parent.CanCollide = true
    script.Parent:Remove()
wait(200)
	script.Parent.CanCollide = false
	    script.Parent:Remove()
	end
deb = false
script.Parent.Touched:connect(function(part)
	if game.Players:FindFirstChild(part.Parent.Name) then
		if deb == false then
			deb = true
			local plr = game.ServerStorage.PlayerMoney:FindFirstChild(part.Parent.Name)
			script.Parent.BrickColor = BrickColor.new("Bright red")
			plr.Value = plr.Value + script.Parent.Parent.Amount.Value
			wait(script.Parent.Parent.TimeToWait.Value)
			deb = false
			script.Parent.BrickColor = BrickColor.new("Bright green")
		end
	end
end)

1 comment

0

Simple fix. :Remove() is deprecated and no longer works. To delete, you now use :Destroy()

1 answer

✓ Accepted answer

Both comments are false: :Remove works just fine (though it is deprecated). :Remove is identical to setting .Parent = nil, if don't you want to destroy something (though in this case, I don't think you want to remove or destroy anything.)

If you merge your scripts, it's much easier to get the behaviour you want:

local deb = false
local enabled = true
script.Parent.Touched:connect(function(part)
    if game.Players:FindFirstChild(part.Parent.Name) then
        if enabled and not deb then
            deb = true
            local plr = game.ServerStorage.PlayerMoney:FindFirstChild(part.Parent.Name)
            script.Parent.BrickColor = BrickColor.new("Bright red")
            plr.Value = plr.Value + script.Parent.Parent.Amount.Value
            wait(script.Parent.Parent.TimeToWait.Value)
            deb = false
            script.Parent.BrickColor = BrickColor.new("Bright green")
        end
    end
end)
while true do
	wait(450)
	enabled = false
	-- You might also want to add some visual change to communicate to the player that it's off, ex:
	script.Parent.Transparency = 0.5
	wait(200)
	enabled = true
	script.Parent.Transparency = 0
end

This discussion is preserved as it was. New answers, comments, and votes are closed.