Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why can't I use brackets inside WaitForChild() ?

I want to use the value of owner instead of the word "Owner" But I can't use brackets inside of WaitForChild() The output is "Workspace.Something.Script:3: Expected identifier when parsing expression, got '['" When I don't use the brackets it tells me "Owner is not a valid member of Players" in the output.

local Something = script.Parent.Something
local Owner = script.Parent.Owner.Value
local Height = game.Players:WaitForChild([Owner]).Stats.Height.Value
local Radius = game.Players.Owner.Stats.Radius.Value

Something.Size.Y = CFrame.new(Height)

1 comment

0

local Height = game.Players:WaitForChild(Owner.Value).Stats.Height.Value

1 answer

✓ Accepted answer

You don't have to use WaitForChild() in this case because we can assume the player is already there. You would usually use WaitForChild() in a LocalScript if you're not sure if something's replicated to the client yet. In this case it'd be better to use FindFirstChild(Owner.Value)

Also, it'd be better to set the Owner variable just to the StringValue object, not the value itself. The way you have it, if the value changed in the Owner object, the variable wouldn't change.

2 comments

0

Maybe I explained it bad. I made a stringvalue called Owner. The value of the stringvalue is EatingToastEveryday. I want to use the name "EatingToastEveryday" not "Owner"

0

Edited my answer

This discussion is preserved as it was. New answers, comments, and votes are closed.