ServerScriptService.Script:9: attempt to index nil with 'Character' - Server - Script:9

Hi I am having a problem with getting a players character

Script

game.ReplicatedStorage.join1.OnServerEvent:Connect(function(plr, joinerName, pName)
	local leader = game.ReplicatedStorage.Parties:WaitForChild(pName).Players:WaitForChild("Party Leader").Value
	local requestFrame = game.Players:FindFirstChild(leader).PlayerGui.PartyGui.PartyGuiScript.request:Clone()
	requestFrame.Parent = game.Players:FindFirstChild(leader).PlayerGui.PartyGui
	requestFrame.Partyname.Value = pName
	requestFrame.TextLabel.Text = joinerName.Name.." Wants To Join Your Party"
	print(joinerName)
	local Player = game:GetService("Players"):FindFirstChild(joinerName)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local torso = Character:WaitForChild("Torso")
	local Humanoid = Character:WaitForChild("Humanoid")
	local Head = Character:WaitForChild('Head')
	Head.Party.Frame.Rank.Text = pName
	game.Players:WaitForChild(joinerName).PlayerGui.PartyGui.PartyGuiFrame.Transparency = 1
	game.Players:WaitForChild(joinerName).PlayerGui.PartyGui.PartyGuiFrame.UIStroke.Thickness = 0
	print(joinerName.Name.." Wants To Join Your Party ("..pName..")")
end)

Error

ServerScriptService.Script:9: attempt to index nil with 'Character' - Server - Script:9```

means that the code is attempting to index something that doesn’t exist try checking the path you created for the property you’re trying to find

Use the Player.CharacterAdded event instead of using Player.CharacterAdded:Wait()

You should tell that to him, not me aha. I tried to help

I just replied to the wrong person, my fault

Ok so in your case, Player is nil. That’s what it means when you attempt to index nil with something. You should try this:

local Player = game:GetService("Players"):WaitForChild(joinerName)

Most likely, the player instance hasn’t fully loaded yet, so you can just use WaitForChild

I retraced it and found out I needed to put .Name

2 Likes