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

The children in workspace won't update when I do workspace:GetChildren()?

Asked by 4 years ago

Before I press "Play", there are 3 things in workspace, Camera, Terrain, Baseplate. When I click play, there are 4 things because my character loads in. In the script below, after adding parts into the workspace after pressing "Play", when I click on the GUI button it prints "its cycling through workspace" 4 times. If I have an extra part in the workspace after clicking "Play", shouldn't it say that 5 times?

My problem is, I need the children to update whenever something is added into workspace during gameplay.

script.Parent.MouseButton1Click:Connect(function()

    w = workspace:GetChildren()

    for i,v in pairs(w) do
        print("its cycling through workspace")
        if v.Name == "Spray" then
            print("The if statement works")
            v:Destroy()
        end
    end 

end)
1
Um. W is the workspace but then its not going to use instance:WaitForchild() . Which means its just looking and seeing the workspace without actually doing anything. voidofdeathfire 148 — 4y
0
Try defining "w" as a local variable. I don't see why this should work but it's in the realm of possibility. Fifkee 2017 — 4y

1 answer

Log in to vote
0
Answered by
Prestory 1395 Moderation Voter
4 years ago

Try this tell me if it doesn't work

script.Parent.MouseButton1Click:Connect(function()

for i,v in pairs(workspace:GetChildren()) do

print("its cycling through workspace")

if v.Name == "Spray" then

print("The if statement works")

v:Destroy()

end

end

end)
Ad

Answer this question