Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 4 years ago

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)

0
Simple fix. `:Remove() ` is deprecated and no longer works. To delete, you now use `:Destroy()` CreationNation1 459 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

Ad

Answer this question