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

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

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

4 comments

0

Try :Destroy()

0

That still does not work, the console says there is soemthing wrong with the first line, but what?

0

well what does it say

0

Check the screenshot in the description of my question called, "The console output`s this"

1 answer

✓ Accepted answer

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) 

1 comment

0

Thankyou for your response, but i am afriad that did not work. The new error in console is: http://pasteboard.co/CJHGSSEzp.png

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