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

How can I track the Target?

Asked by 6 years ago

When a the server is started, lets say there's a Part in Workspace and it gets RandomPart(1-3) (picks a random name for it) The RandomPart has a Target that i'm trying to get. But it's random and the targets for each RandomPart are the same. I want to get the target for any RandomPart. It could be any. All I need is that one Target. How would I do this? I tried this but it doesn't work.

Workspace > Part > RandomPart1 > Target

Workspace > Part > RandomPart2 > Target

Workspace > Part > RandomPart3 > Target

for i,v in pairs(game.Workspace.Part:GetChildren()) do
    Targetfound = v:FindFirstChild('Target')
end

Targetfound.BrickColor = BrickColor.new('Really red')

1 answer

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

-- So it's actually random math.randomseed(tick()%1*1e6) -- Use WaitForChild() on children local folder = workspace:WaitForChild("Part") local function find_target() -- Choose random part in the folder local all = folder:GetChildren() local rand = all[math.random(#all)] local target = rand:findFirstChild("Target") if target then target.BrickColor = BrickColor.new("Really red") return target end return false end local target = find_target() print(target and 'Found the target' or "Target not found")
Ad

Answer this question