You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to get the character of a player so I can check to see if the humanoid died
What is the issue? Include screenshots / videos if possible!
I dont know how to get the character of a player from server side.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried looking on dev forum but everyone keeps saying that you should use player.Character but that is if you are doing it on local script which in my case i’m not. (I also don’t want to use remote events in my case)
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- This is an example Lua code block
local player = game:GetService("Players"):GetChildren()
player.Character.Humanoid.Died:Connect(UpdateTeamGUI)
I get the error attempt to index nil with Humanoid which means that the character can’t be found.
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
game.Players.PlayerAdded:Connect(function(player)
local Character = player.Character or player.CharacterAdded:Wait();
local Humanoid = Character:FindFirstChild('Humanoid');
Humanoid.Died:Connect(UpdateTeamGUI);
end)
GetChildren will return you a table of all the children(In this case the players). Character is a propertie of player. You are tring to get character from the players table.
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local human = char:WaitForChild("Humanoid")
human.Died:Connect(UpdateTeamGUI)
end)
end)
Its humanoid not humanoidRootPart.
game.Players.PlayerAdded:Connect(function(AddedPlayer)
local Character = AddedPlayer.Character or AddedPlayer.CharacterAdded:Wait();
local Humanoid = Character:FindFirstChild('Humanoid');
Humanoid.Died:Connect(UpdateTeamGUI);
end)
In the function I have the argument as player and basically the function chooses the team you are going to be on and the function is called inside the player added function and the error I get is this, attempt to index nil with ‘TeamColor’
I am bumping this topic since nobodies posts have been marked ‘Solution’ and I may be able to provide a coding example that may possible help out in this situation.
This is one way of getting the players character inside a server-script. Once the player is added into the game we then get that players character, after we have the character of that player, we then get that players humanoid and it will fire some code if it has died:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character.Humanoid
Humanoid.Died:Connect(UpdateTeamGUI)
end)
end)
You could also use :GetPlayerFromCharacter() but the example I have displayed above should work perfectly.