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

My script is failing to delete the BasicUpgrader1B, for some reason?

Asked by 7 years ago

The following script, will not delete the BasicUpgrader1B for some reason, and i do not quite know why:

model1 = script.Parent.Parent.Parent.BasicUpgrader1B
model2 = script.Parent.Parent.Parent.BasicUpgrader1A
model3 = script.Parent.Parent.Parent.BasicUpgrader1C
UpgradeCost = 150

upgradeStuff1 = model1:clone()
upgradeStuff2 = model2:clone()
upgradeStuff3 = model3:clone()

wait(1)

model1:remove()
model2:remove()
model3:remove()
owner = script.Parent.Parent.Parent.OwnerName
local ting = 0

function onTouch(hit)
    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("Cash")
                    if cash.value > (UpgradeCost-1) then
                        cash.Value = cash.Value - UpgradeCost
                        upgradeStuff1.Parent = script.Parent.Parent.Parent
                        upgradeStuff2.Parent = script.Parent.Parent.Parent
                        upgradeStuff3.Parent = script.Parent.Parent.Parent
                        script.Parent.Parent:remove()
                    end
                end
            end
        end
        ting = 0
    end
end

script.Parent.Touched:connect(onTouch) 

This is my explorer view: http://pasteboard.co/CHHkQRgVh.png

The console output's this: http://pasteboard.co/CHI7TUewb.png

0
Try :Destroy() TheePBHST 154 — 7y
0
That still does not work, the console says there is soemthing wrong with the first line, but what? georgeashby11221 9 — 7y
0
well what does it say Perci1 4988 — 7y
0
Check the screenshot in the description of my question called, "The console output`s this" georgeashby11221 9 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago

The problem is most likely that the script is executing before the model has even loaded in.

We can fix this by waiting for each individual model before carrying out the function.

model1 = script.Parent.Parent.Parent:WaitForChild("BasicUpgrader1B")
model2 = script.Parent.Parent.Parent:WaitForChild("BasicUpgrader1A")
model3 = script.Parent.Parent.Parent:WaitForChild("BasicUpgrader1C")
UpgradeCost = 150

upgradeStuff1 = model1:clone()
upgradeStuff2 = model2:clone()
upgradeStuff3 = model3:clone()

wait(1)

model1:remove()
model2:remove()
model3:remove()
owner = script.Parent.Parent.Parent.OwnerName
local ting = 0

function onTouch(hit)
    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("Cash")
                    if cash.value > (UpgradeCost-1) then
                        cash.Value = cash.Value - UpgradeCost
                        upgradeStuff1.Parent = script.Parent.Parent.Parent
                        upgradeStuff2.Parent = script.Parent.Parent.Parent
                        upgradeStuff3.Parent = script.Parent.Parent.Parent
                        script.Parent.Parent:remove()
                    end
                end
            end
        end
        ting = 0
    end
end

script.Parent.Touched:connect(onTouch) 
0
Thankyou for your response, but i am afriad that did not work. The new error in console is: http://pasteboard.co/CJHGSSEzp.png georgeashby11221 9 — 7y
Ad

Answer this question