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

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

Asked by 5 years ago

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.

0
Why do you want to change its parent and destroy it at the same time? Endergenius100 12 — 5y
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. User#24403 69 — 5y
0
In less words, your box is being destroyed instead. User#24403 69 — 5y
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 TheOneKingx 7 — 5y
View all comments (2 more)
0
Oh i see, so the box does get destroyed. TheOneKingx 7 — 5y
0
yeah User#24403 69 — 5y

1 answer

Log in to vote
0
Answered by
metryy 306 Moderation Voter
5 years ago
Edited 5 years ago

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) 

0
Calling, not firing. Fire refers to an event notifying its listeners. User#24403 69 — 5y
0
Fixed, thanks for pointing that out. metryy 306 — 5y
Ad

Answer this question