There are two referencing of character that i wrote. One is having the error "attempt to index nil with 'Humanoid'"
local player = game:GetService("Players") local localplayer = player.LocalPlayer local character = localplayer.Character
and another one is having this error: Infinite yield possible on 'Players.AriyanHacker29:WaitForChild("Character")
local player = game:GetService("Players") local localp = player.LocalPlayer local character = localp:WaitForChild("Character")
any sort of help will be appreciated!!
Hey there! Answer to first one:
local player = game:GetService("Players") local localplayer = player.LocalPlayer localplayer.CharacterAdded:Wait() local character = localplayer.Character
Character is not a child of player, as far as I'm concerned. So WaitForChild
won't work
and your calling the character before it spawns
The reason why this wouldn't work if because Character
isn't a child of Player
. The player and character do have a connection but are not directly connected. Here are ways to get a player's character:
In a server script:
game.Players.PlayerAdded:Connect(function(plr) plr.CharacterAdded:Connect(function(char) --char refers to the player's character end) end)
Local script:
local plr = game.Players.LocalPlayer repeat wait() until plr.Character local char = plr.Character --events with char being the character
Is this a server script? Because you cant get LocalPlayer From a server Script.