How do i get the character from Localplayer through a normal script?

I’ve been trying to get the character from Localplayer through a normal script, but it just kept going back saying saying Attempt to index nil with “Character”

Does anyone have a solution to this?

LocalPlayer doesn’t exist on the server, you’re probably better off checking for player joins and doing it from there

local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
  player.CharacterAdded:Connect(function(character)
    -- character stuff here
  end)
end)
2 Likes

On the server, LocalPlayer doesn’t exist. Instead you can listen for PlayerAdded and then wait for the character.


game.Players.PlayerAdded:Connect(function(player)
    local character = player.Character or player.CharacterAdded:Wait()

    -- Do something with the character
end)

2 Likes

The question you need to answer is: which player?

From the perspective of the server(a normal script) the world doesn’t rotate around a specific player(like local scripts), so you need to figure out a way to distinguish what player/players you’re looking for in order to get your answer. Are you looking for players that join the game? For players that reset/respawn? For players that fire a specific event or perform a specific action?

When you figure out to what thing the player you’re looking for is relative to, there will be code that helps you find them. For local scripts the player is relative to the current machine running Roblox.

Without more context this is hard to answer

1 Like