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

".." Won't work to get a player by text in a textbox?

Asked by 5 years ago

So normally on ROBLOX you can just do

game.Players..ITEM.Text 

etc..

For some reason this is not working, I tried something different but it won't work and nothing appears in "Output" The code is as followed.

local namelol = script.Parent.Parent.Name.Text
local row = script.Parent.Parent.Row.Text
local num = script.Parent.Parent.SeatNumber.Text


script.Parent.MouseButton1Click:Connect(function()
    if row == "A" and num == 1 then
        game.Players.namelol.Character.HumanoidRootPart.CFrame = workspace.A_One.CFrame * CFrame.new(0, 3, 0)
    else
        if row == "A" and num == 2 then
            game.Players.namelol.Character.HumanoidRootPart.CFrame = workspace.A_Two.CFrame * CFrame.new(0, 3, 0)
        else
            if row == "A" and num == 3 then
                game.Players.namelol.Character.HumanoidRootPart.CFrame = workspace.A_Three.CFrame * CFrame.new(0, 3, 0)
            end
        end
    end

end)

I do know how to script and all that but I can't find an object via something's text.

2 answers

Log in to vote
1
Answered by 5 years ago

If you want to index objects w/ dynamic strings, then you can use FindFirstChild() or square brackets [ ].

Ex:

game.Players:FindFirstChild(namelol).Character.HumanoidRootPart.CFrame
game.Players[namelol].Character.HumanoidRootPart.CFrame
0
You might want to define the variables within the event callback though, so it'll be the most recent text of the objects. ScrewDeath 153 — 5y
0
Thank you very much for your answer! JamiethegreatQ777 16 — 5y
Ad
Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago

You're indexing the player's name the wrong way. Instead, you should use square parantheses [ ]. Like this:

game.Players[namelol].Character.HumanoidRootPart.CFrame = workspace.A_One.CFrame * CFrame.new(0, 3, 0)

Answer this question