WaitForChild is not a valid member of RBXScriptSignal

Hello.

I’m trying to test out Character variables, since I’ve never actually done so. Everytime this script runs, it errors. Here’s the script.

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

LocalPlayer.CharacterAdded:Connect(function()
	Character = LocalPlayer.Character
end)

Character:WaitForChild("Humanoid").Died:Connect(function()
	print("Died!")
end)

What could I do to fix this? I’ve tried setting Character to this…

local Character = LocalPlayer.Character

But then it errors with something else.

LocalPlayer.CharacterAdded Returns a RBXScriptSignal not the character. Also when you don’t include that you are trying to get the character before it exists. You need to wait for the character to get added. You can probably just add :Wait() to the end of that .CharacterAdded

2 Likes

Thank you, I did so. Would you happen to know how to keep the function binded to Humanoid.Died? It unbinds once the player dies once.

if not game:GetService("Players").LocalPlayer.Character then
	game:GetService("Players").LocalPlayer.CharacterAdded:Wait()
end

local LocalPlayer = game:GetService("Players").LocalPlayer
local Character = LocalPlayer.Character

LocalPlayer.CharacterAdded:Connect(function()
	Character = LocalPlayer.Character
end)

Character:WaitForChild("Humanoid").Died:Connect(function()
	print("Died!")
end)

Yeah bind it inside character added. That way it will re-bind it whenever the character respawns. You will probably have to do a wait for child for the humanoid though.

1 Like