#GetDescendants() not finding folder in player.Character

1 messages · Page 1 of 1 (latest)

opaque rose
#

I'm unsure of why the GetDescendants() isn't finding the folder.
Here is the script code:

local userInput = game:GetService("UserInputService")

--VARIABLES/REFERENCES:
local angleBasedCursor_RE = game.ReplicatedStorage:WaitForChild("giveAngleBasedCursor1")
local camBasedCursor_RE = game.ReplicatedStorage:WaitForChild("giveCamBasedCursor1")
local angleBasedCursor_S = game.ReplicatedStorage:WaitForChild("AngleBasedCursor1")
local camBasedCursor_S = game.ReplicatedStorage:WaitForChild("CamBasedCursor1")
local player = game.Players.LocalPlayer
local debounce = false

--FUNCTIONS:
camBasedCursor_RE.OnServerEvent:Connect(function(player)
    
    print(player.Name .. " was given Cam-Based Cursor.")
    
    if not debounce then
        debounce = true
    
        local newCursor = camBasedCursor_S:Clone()
        newCursor.Parent = player.Character
        newCursor.Name = "Cursor"
        
        for i,v in (player.Character:GetDescendants()) do
            if v:IsA("Folder") then
                print("something")
                v:Destroy()
            end
        end
        
        wait(1)
        
        debounce = false
    end
end)

angleBasedCursor_RE.OnServerEvent:Connect(function(player)
    
    print(player.Name .. " was given Angle-Based Cursor.")
    
    if not debounce then
        debounce = true        
    
        local newCursor = angleBasedCursor_S:Clone()
        newCursor.Parent = player.Character
        newCursor.Name = "Cursor"
        
        for i,v in (player.Character:GetDescendants()) do
            if v:IsA("Folder") then
                print("somethin again")
                v:Destroy()
            end
        end
        wait(1)
        
        debounce = false
    end
end)```
rain sinew
#

lowkey that cursor thing is a sick concept

#

the :GetDescendants() retuns a table, you'll have to use pairs to traverse it properly

#
for _, v in pairs(player.Character:GetDescendants()) do
  ...
end
#

it kinda late response but whatever😭

opaque rose
rain sinew
#

oh mb💀 I didn't look at the whole script, I'll double check

#

I don't think it is at all brokennn i think there is just no folders

#

maybe print out your decendants and it might tell you more about what ur deleting

opaque rose
#

bcuz its not like a checking too early thing

#

since the cursors do stop following the player once a new one is created

#

but they just wont leave the workspace because nothing is de-parenting them

rain sinew
#

try print v.ClassName in the loop before you check if it IsA("Folder")

#

see if it returns folder

#

at all

opaque rose
#

i even searched for "Folder" but 0 matches

rain sinew
#

I checked documentation and the Folder instances should be returned by GetDecendants so its a bit weird

#

when you test go into server mode and see if you still see the instances

#

I don't know why you wouldn't but maybe?

opaque rose
#

Idk it might be a scope thing

rain sinew
#

if so you can try have another remote event to tell the client to destroy it there

opaque rose
#

Ah ok

#

I'll try that next then

rain sinew
#

so you didn't see it on the server?

opaque rose
#

I wouldnt know, not at computer no more

rain sinew
#

goodluck lol

opaque rose
#

thx

swift drum
#

you need to use onclientevent on the client

opaque rose