Hi! This is a very basic question, but I'm very new to scripting. I have already assigned a variable to the person playing's name property (LocalPlayer.name), but I now want to use that to get to the player's model in the workspace. This is what I have:
local playername = game.Players.LocalPlayer.name function teleport() game.Workspace.playername.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0,50,0)) end
Now, I know the issue is that I can't simply put "workspace.playername," because it looks for an object called "playername" in the workspace. If I put in my own username, the script works perfectly fine. Is there any other way that I can accomplish this using the name of the person playing?
To index anything with a non-string, use brackets. e.g. workspace[playername]
However the solution is to use the property LocalPlayer.Character, which gets the workspace model you want. Do not try to use names because if a different object has their name you will get wrong results.