Why variable be 1 upper above the parent after got if statement?

so i wanna detect if player leave using local script but the only issue is the variable become 1 upper after i declarate if statement
this is the code

local billboard = game.ReplicatedStorage.BillboardGui

player.CharacterAdded:Connect(function(character)
	local billboardclone = billboard:Clone()
	billboardclone.Parent = character:WaitForChild("Head")
end)

game.Players.PlayerRemoving:Connect(function(playerleave)
	if player == playerleave then
	        print(player.Character) 
		print(player.LocalPlayer.Character)
	end
end)

output:

 15:42:52.881  RahmatHidayat2154  -  Client - handler:11
  15:42:52.883  LocalPlayer is not a valid member of Player "Players.RahmatHidayat2154"  -  Client - handler:12
  15:42:52.883  Stack Begin  -  Studio
  15:42:52.883  Script 'Players.RahmatHidayat2154.PlayerScripts.handler', Line 12  -  Studio - handler:12
  15:42:52.884  Stack End  

If player is already defined as a player, then you cannot do player.LocalPlayer because LocalPlayer is not a valid property of the Player class.

im sorry but i guess you are misunderstanding, i mean the player.localplayer.name work than player.name because the player.name just return error

That’s not correct.

Based on the error and the provided code, then player represents the local player, and hence player.LocalPlayer (the equivalent of game.Players.LocalPlayer.LocalPlayer) doesn’t exist.

wait, im just realized its line 11 not 10 lol, im sorry

1 Like