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

Object remove() not working, probably not using it correctly?

so im doing a tycoon, and its a multistage tycoon, so ive got wood walls u will buy in the very beginning which are small, then a little bit in you unlock stone walls which cover a larger area

im intending it to remove the wood walls and add the stone walls, well right now it adds the stone but doesnt remove the wood, tho it does remove the wood wall if i left it active, but if the wood wall is spawned in with a tycoon, then i attemt to remove it with the stone wall button it doesnt remove it

here is both scripts, any help figuring out the problem is appreciated :)

WOOD WALL SCRIPT

-------------------------------------------------------------------------------------------------------------------------
model = script.Parent.Parent.Parent.WoodAge.WoodWalls

Upgradecost = 0
-------------------------------------------------------------------------------------------------------------------------
upgradeStuff = model:clone()

wait(1)

model:remove()
owner = script.Parent.Parent.Parent.OwnerName 
local ting = 0

function onTouched(clicked)
    hit = clicked.Character.Head
    if ting == 0 then
    ting = 1
    check = hit.Parent:FindFirstChild("Humanoid")

    if check ~= nil then
    if hit.Parent.Name == owner.Value then
        local user = game.Players:GetPlayerFromCharacter(hit.Parent)
        local stats = user:findFirstChild("leaderstats")

        if stats ~= nil then
            local cash = stats:findFirstChild("Gold")
            if cash.Value > (Upgradecost-1) then

                cash.Value = cash.Value - Upgradecost
                upgradeStuff.Parent = script.Parent.Parent.Parent
                script.Parent.Parent:remove()

            end
        end
    end
    end

    ting = 0
    end
end

script.Parent.ClickDetector.MouseClick:connect(onTouched)

STONE WALL SCRIPT

-------------------------------------------------------------------------------------------------------------------------
Wall = script.Parent.Parent.Parent.WoodAge.WoodWalls
model = script.Parent.Parent.Parent.MidStone.SmallCastle
Upgradecost = 0
-------------------------------------------------------------------------------------------------------------------------
upgradeStuff = model:clone()

wait(1)

model:remove()
owner = script.Parent.Parent.Parent.OwnerName 
local ting = 0

function onTouched(clicked)
    hit = clicked.Character.Head
    if ting == 0 then
    ting = 1
    check = hit.Parent:FindFirstChild("Humanoid")

    if check ~= nil then
    if hit.Parent.Name == owner.Value then
        local user = game.Players:GetPlayerFromCharacter(hit.Parent)
        local stats = user:findFirstChild("leaderstats")

        if stats ~= nil then
            local cash = stats:findFirstChild("Gold")
            if cash.Value > (Upgradecost-1) then

                cash.Value = cash.Value - Upgradecost
                upgradeStuff.Parent = script.Parent.Parent.Parent
                script.Parent.Parent:remove()
				Wall:remove() -- this is where i try to remove the wooden wall

            end
        end
    end
    end

    ting = 0
    end
end

script.Parent.ClickDetector.MouseClick:connect(onTouched)

2 comments

0

Any output?

0

if i define the group above doing Wall = script.Parent.Parent.Parent.WoodAge.WoodWalls then no but if i do script.Parent.Parent.Parent.WoodAge.WoodWalls down where Wall:remove() is then it says attempting to index nil Parent

3 answers

to make life easier why dont you just keep the same wall increase the size change the offset so it doesnt bleed through any other blocks and change its properties.

Try using model:Destroy() instead?

2 comments

0

doesnt do anything :/

0

Tycoon scripts actually take advantage of remove being depricated and it leaving a little bit behind.

Remove is horrible, and never works. What you want to do is replace "remove()" with "Destroy()".

-- Destroy() must be capitalized correctly.
-- Destroy() is about the same as remove(), but better.
-- Destroy() ftw.
game.Workspace.Part:Destroy()

2 comments

0

like i said above, Destroy() didnt change anything, its still not removing the wall

0

Tycoon scripts actually take advantage of remove being depricated and it leaving a little bit behind.

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