So I keep getting this error saying “Workspace.Player1.LocalScript:4: attempt to index nil with ‘Character’”. THe script is in a local script inside StarterCharacterScripts and the way I tried getting the character is
local plr = game.Players.LocalPlayer
local character = plr.Character
local plr = game.Players.LocalPlayer
local char = plr.Character
local head = char:WaitForChild("Head")
local event = game.ReplicatedStorage:WaitForChild("LocalPlayer")
event.OnClientEvent:Connect(function(player)
local headFolder = player.Character:WaitForChild("headContainer")
end)
local Character = script.Parent
local head = Character:WaitForChild("Head")
local event = game.ReplicatedStorage:WaitForChild("LocalPlayer")
event.OnClientEvent:Connect(function(player)
local headFolder = Character:WaitForChild("headContainer")
end)
local player = game:GetService('Players').LocalPlayer
local char = script.Parent
local head = char:WaitForChild('Head')
local event = game:GetService('ReplicatedStorage'):WaitForChild('LocalPlayer')
event.OnClientEvent:Connect(function(targetPlayer)
if targetPlayer.Character ~= nil then
local headFolder = targetPlayer.Character:WaitForChild('headContainer')
end
end)
This problem is probably because the script is running faster than the character can load in, so the script error’s when looking for the player’s character because the character does not exist yet.
I’m assuming this is all being run in a local script. Given that, where is this local script located (ie, StarterPlayerScripts, StarterCharacterScripts)?