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

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

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

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.

2 comments

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

0

I generally stay away from while loops as you can usualy do most of the tasks with the changed event

``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

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