"Players.kdopdaux1803.PlayerScripts.LocalScript:8: attempt to index nil with 'Humanoid'" + How to make a Part make from ReplicatedStorage to Workspace

Hello guys i have another issue when i tried to help @PuffyJasonrocks84.

However the issue is when i type “Humanoid” it just won’t let it work.

The script:

--// Settings \\--
local ReplicatedStorage = game:FindFirstChild("ReplicatedStorage")
local Players = game.Players
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character

--// Scripting the Character \\--
if Character.Humanoid.Health == 0 then
	-- Add anything in here !
end

Couldn’t find any images because it already says it on the title.

Anyways, any help is appreciated.

Edit: Edited the title.

have you tried
local Character = LocalPlayer.Character or LocalPlayer.CharactedAdded:Wait()

also why are you doing “if Character.Humanoid.Health == 0” immediately after defining what “Character” is

Why ? Because i want to make the Part in ReplicatedStorage to Clone In.

Still errors, and it errors before Line 8.

it won’t fire when the player is killed; that will check once if the player has 0 hp as soon as the player’s character spawns in

Do this instead

game.Players.LocalPlayer.Character.Humanoid.Died:Connect(function()
	
end)
1 Like

Okay but you can remove the “-- Add anything in here !”. Thanks for the suggestion.

But unfortunately, it still errors.

1 Like

It is Working for me perfectly Please add it in StarterCharacterScripts.
Make sure it’s a Local script to.

1 Like

if it’s in there, then you don’t need to use LocalPlayer.Character you should however use:

script.Parent.Humanoid.Died:Connect(function()
	
end)
1 Like

Yes, I know I just like it writing it in that way.
Both should work tho.

Thanks for the suggestion at last, i putted on StarterPlayerScripts and somehow didn’t not worked but with the suggestion to put the LocalScript from StarterPlayerScripts to StarterCharacterScripts it worked perfectly fine, although, i just wanted to make a Part but when you die it actually spawn the Part in Workspace that can’t be collected until you respawn.

Sorry if i remove the solution after this quickly :frowning:

Oh, That’s still simple What you could do is to detect when the Character gets added, (Fires when the Player joins the game and When the Player resets to)

Add a Server script inside of ServerScript Serivce.

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Char)
		-- the Player character got added.
	end)
end)

This ?

script.Parent.Humanoid.Died:Connect(function()
	game.Players.PlayerAdded:Connect(function(Player)
		Player.CharacterAdded:Connect(function(Char)
			-- the Player character got added.
		end)
	end)
end)

Oh, you want it a Local script that’s fine then add a Local script inside of StarterPlayer script and add this code

repeat
	task.wait(.1)
until game.Players.LocalPlayer.Character

game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Died:Connect(function()
	game.Players.LocalPlayer.CharacterAdded:Connect(function(Char)
		-- added
	end)
end)

Doesn’t seems to work…

This text will be blurred

Make sure it’s a local script inside of StarterPlayerScripts (NOT StarterPlayer).
I’ve also tested it and it Works Perfectly.

Picture of it working
Picture of Code

Picture of it printing after I reset and Respawn
image

Like no. You need to connect an event to Humanoid death AND wait for the humanoid to be there when you try to access it ( Also what are those comments lol ).

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()

Character:WaitForChild("Humanoid").Died:Once(function()
	-- Add anything in here !
end)


It only worked when you respawn, have you said it wrongly?

Yes, lol My bad.

If i’m smart enough, this will error for sure.