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

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

Asked by
nicros 165
9 years ago

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)
0
Any output? FearMeIAmLag 1161 — 9y
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 nicros 165 — 9y

3 answers

Log in to vote
0
Answered by 9 years ago

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.

Ad
Log in to vote
-1
Answered by
Mr1Vgy 30
9 years ago

Try using model:Destroy() instead?

0
doesnt do anything :/ nicros 165 — 9y
0
Tycoon scripts actually take advantage of remove being depricated and it leaving a little bit behind. HungryJaffer 1246 — 9y
Log in to vote
-1
Answered by 9 years ago

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()
0
like i said above, Destroy() didnt change anything, its still not removing the wall nicros 165 — 9y
0
Tycoon scripts actually take advantage of remove being depricated and it leaving a little bit behind. HungryJaffer 1246 — 9y

Answer this question