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

Destroy() glitches sometimes so i want to know if this method works?

So i'm trying to make part disappear by using Destroy() but sometimes it glitches and it doesn't destroy the part immediately so i tried doing this instead

Box.Parent = game.ServerScriptService and Box:Destroy()

If i do this then the part would immediately disappear but i'm not sure if the part would get destroyed once ServerScriptService becomes it's parent.

6 comments

0

Why do you want to change its parent and destroy it at the same time?

0

x and y will evalúate to x if x is falsey, y otherwise. A falsey value is false or nil. Anything that is not false or nil is truthy. Since ServerScriptService is not false or nil it is truthy. :Destroy() has no return value, and since you're trying to store the result of a void function in a variable, the variable holds nil instead.

0

In less words, your box is being destroyed instead.

0

As i stated, destroy gets glitched sometimes but changing it's parent doesn't so i'm wondering if the part will still get destroyed if i change it's parent

0

Oh i see, so the box does get destroyed.

0

yeah

1 answer

Destroy shouldn't glitch, it may be a problem with how you're calling the function.

local function Remove(obj)
	if obj:IsA("LuaSourceContainer") then
		obj.Disabled = true 
	end

	obj.Parent = nil
end

-- Example:
Remove(box)	
	

2 comments

0

Calling, not firing. Fire refers to an event notifying its listeners.

0

Fixed, thanks for pointing that out.

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