I tried to do it this way and it didn't work. whats the correct way?
local char = game.Workspace.Player.Name
The only foolproof way to find a player in the Workspace is to use GetPlayerFromCharacter()
on the model that you assume is the player's Character. Furthermore, you'd be using FindFirstChild()
before this to check if there is something in the Workspace with the player's name. Now, this is not a site where we give you code; we help you with existing code. As such, this is all I'm giving you.
If you are using a local script then you can just do:
local player = game.Player.LocalPlayer
local plr = game.Workspace:FindFirstChild(player.Name)
There's a property in the Player
named Character
which will give the model instance or nil.
Sample of using Character
local Player = game.Players:FindFirstChild(name) local char = Player.Character