Hello.today i was testing something and did a really easy script:
local Players = game:GetService(“Players”)
local CurrentCam = workspace.CurrentCamera
local Camera = workspace.Camera
local LocalPlayer = Players.LocalPlayer
local function onPlayerAdded(Player)
if LocalPlayer then
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded
local Humanoid = Character:WaitForChild(“Humanoid”)
if Humanoid then
print(“Hum Found”)
end
end
end
if LocalPlayer then
print(“Yes”)
onPlayerAdded()
end
The function should be fired if there is a LocalPlayer,but it isn’t working. i tried to print words to make sure the script gets the LocalPlayer, but it doesn’t print. I used the Player Added func too but it doesn’t work either. i readed a few posts with people with my same problem but i still couldn’t find an answer/fix. The script is just a LocalScript in StarterPlayerScripts.
thanks in advance for any help/answers.
If this is a localscript, the LocalPlayer should always exist because Player objects cant randomly be destroyed unless player leaves
local Players = game:GetService(“Players”)
local Camera = workspace.CurrentCamera
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayerCharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
print(Humanoid:GetFullName())
local Players = game:GetService("Players")
local Camera = workspace.Camera
local CurrentCamera = workspace.CurrentCamera
local Client = Players.LocalPlayer
local Character = Client.Character or Client.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid then
print("Found humanoid in client's character")
end
There’s no need to use the PlayerAdded event since the LocalPlayer will always exist in the game.Players data model. Although there’s no guarantee that it is fully loaded, it will always be present.
In this scenario, you can employ custom workarounds to detect if a player has been fully loaded, such as using Client:WaitForChild(“PlayerGui”). However, please avoid attempting to use this solution from the local client to index PlayerGui from other players as it is not replicated between clients.