KuLh
(Space Cowboy)
May 26, 2019, 3:33am
#1
I have created a part on client only, and I want it to be removed after 1 second of being parented to game.Workspace
. This would seem very simple and easy, but I have tried using the Debris:AddItem
method, as well as Instance:Destroy()
I am trying to remove this part via Local Script.
I do not understand why this is not as simple as it should be.
1 Like
sozzly
(sozzly)
May 26, 2019, 3:52am
#2
do you have a reference to the part, then once you have a reference, are you calling :Destroy() (or debris:AddItem) on that part?
2 Likes
KuLh
(Space Cowboy)
May 26, 2019, 4:01am
#3
A reference from another script, yes.
1 Like
sozzly
(sozzly)
May 26, 2019, 4:02am
#4
hmm, could i see the code please?
2 Likes
KuLh
(Space Cowboy)
May 26, 2019, 4:03am
#5
The one referencing the part, or the one attempting to remove it?
1 Like
sozzly
(sozzly)
May 26, 2019, 4:03am
#6
Xensez:
attempting to remove it?
the one referencing the part and the one attempting to remove it
2 Likes
KuLh
(Space Cowboy)
May 26, 2019, 4:07am
#7
The local script that references it is very large, so here is the snippet that involves it.
--local part place
local function makePartm()
localpart = Instance.new("Part")
localpart.Size = part.Size
localpart.Material = part.Material
localpart.BrickColor = part.BrickColor
localpart.Position = part.Position
localpart.Anchored = true
localpart.CastShadow = false
localpart.Parent = part.Parent
localpart.BackSurface = Enum.SurfaceType.Weld
localpart.BottomSurface = Enum.SurfaceType.Weld
localpart.FrontSurface = Enum.SurfaceType.Weld
localpart.LeftSurface = Enum.SurfaceType.Weld
localpart.RightSurface = Enum.SurfaceType.Weld
localpart.TopSurface = Enum.SurfaceType.Weld
localpart:MakeJoints()
localpart.Anchored = false
end
The local script attempting to removed it (currently a mess):
local Debris = game:GetService("Debris")
while wait() do
game:GetService("Debris"):AddItem(game.Workspace.Part, 1)
end
game.Workspace.DescendantAdded:Connect(function(part)
print("hey")
if part.ClassName == "Part" and part.Name == "Part" and not (part:FindFirstChild("SelectionBox")) then
print("debris?")
Debris:AddItem(part,1)
end
end)
1 Like
KuLh
(Space Cowboy)
May 26, 2019, 4:10am
#8
Let me try setting the reference to nil after executing its purpose, then removing the part via the other script.
1 Like
KuLh
(Space Cowboy)
May 26, 2019, 4:12am
#9
setting it to nil was useless.
1 Like
sozzly
(sozzly)
May 26, 2019, 4:18am
#10
try putting a spawn wrapping around the while wait loop, see if that works
2 Likes
1Joeb
(joe)
May 26, 2019, 4:20am
#11
Your function is never getting called
2 Likes
KuLh
(Space Cowboy)
May 26, 2019, 4:23am
#13
the makePartm() function gets called in the full script, and the part is created, as intended.
Though the other script doesnāt even print anything. I assume the function doesnāt work locally, but I canāt find any other way that does work locally.
1 Like
sozzly
(sozzly)
May 26, 2019, 4:24am
#14
the while loop is possibly causing the workspace.DescendantAdded from not working, so, try wrapping a spawn(function() on the while loop
2 Likes
1Joeb
(joe)
May 26, 2019, 4:25am
#15
Why are you running a loop that adds a random brick named āPartā in the workspace to debris?
2 Likes
KuLh
(Space Cowboy)
May 26, 2019, 4:26am
#16
Iāve tried both of your suggestions, none workā¦
This is now currently the remove script:
game.Workspace.DescendantAdded:Connect(function(part)
print("hey")
if part.Name == "TrashBlock" then
print("debris?")
part:Destroy()
end
end)
This prints nothing to my log.
1 Like
Ripull
(Ripull)
May 26, 2019, 4:29am
#17
Inside the DescenantAdded function put a wait() before the Part.Name check
3 Likes
KuLh
(Space Cowboy)
May 26, 2019, 4:33am
#18
Wow guysā¦ I canāt believe how simple this was. The local script that was attempting to remove it, was parented to Workspace.
I moved it into my GUI element, and it started working perfectly.
I love when the little things cause such disasterš
6 Likes