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

Trying to find certain objects in the workspace(sound) by using its classname?

Asked by 6 years ago
Edited 6 years ago

Im trying to create a script to look for any objects with the classname Sound in the workspace but idk how to do it i tried using findfirstchild but it only finds using the name, not the classname?

like i can use this but it only finds it using the name of it not classname

local found = workspace:FindFirstChild("Sound",true) if found then found.PlaybackSpeed = 0.5 end

2 answers

Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
6 years ago

There's a function called 'FindFirstChildOfClass'.

local sound = workspace:FindFirstChildOfClass('Sound')

if sound then sound.PlaybackSpeed = 0.5 end
0
how can i make it search the whole workspace, like if the sound is on a part or in a folder ATestAccount420 31 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

There is a property of all instances called GetDescendants. You can use this like so,

for i,v in pairs(workspace:GetDescendants()) do
    if v.ClassName == "Sound" then
        --Do Stuff
    end
end

Answer this question