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

This script deletes the brick and spams erros of parent being nil like 8?

Asked by 8 years ago
Edited 8 years ago

Basically this is a Gui and it creates a frame it moves etc now when it gets to a certain position i want the frame to be removed now this works

-- Start of script while true do if script.Parent.Position.X.Offset ~= 260 then wait(.1) else if script.Parent.Position.X.Offset == 260 then

    script.Disabled = true
    script:Destroy()
script.Parent:Destroy()
    end
end
end

-- End of script

BUT It spams that Parent(script.Parent:Destroy()) is a Nil value in the output which tends to cause stress in game is their an easier way to delete them without this error?

2 answers

Log in to vote
0
Answered by 8 years ago

I do not know why you are getting this error but its best if you stop the processing.

You can use 'break' to exit a loop safely and resume the next code block.

while wait(0.1) do  -- wait is no in the while loop so we dont need to check it this will be read as true
    if script.Parent.Position.X.Offset == 260 then -- this may be a problem if you do not has Offser 260 you may want to use >= ?
        script.Parent:Destroy() -- destroy  the parent
        break -- exit this loop so the rest of the code can run
    end
end

script:Destroy() -- if you wanted to remove the script but it is inactive

Hope this helps, pls comment if you do no understand this code.

0
I do understand i actually fixed it alot easier See before i was doing one script to create the instance.new("Frame") and this script that i posted wasi n anotehr script parent to script and i cloned it into the brick ZachRBLX 10 — 8y
0
I generally stay away from while loops as you can usualy do most of the tasks with the changed event User#5423 17 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

``function del()

        local Frames = script.Parent:GetChildren()
for i=1, #Frames do
    if Frames[i].Name == "Square" then
        if Frames[i].Position.X.Offset == 260 then
        Frames[i]:Destroy()

        else if Frames[i].Name == "Square" then
            if Frames[i].Position.X.Offset ~= 260 then
        wait(0.1)

    end
    end
end
    end
end
end



while true do 
    wait()
    thing()
    del()

end

This is what i ended up doing don't mind thing(_) its another function above this part in the script

Answer this question