I have a localscript that is inside a player's character. When the player's character dies its supposed to print("Died"), unequip the tool it is holding and fire a remote event. However what happens is that when the character dies, it says attempt to call a nil value. Could someone tell me why it says this?
local plr = game.Players.LocalPlayer local char = plr.Character local ReplicatedStorage = game:GetService("ReplicatedStorage") local Attack = ReplicatedStorage:WaitForChild("StarterToolsOnDeath") if char.Humanoid.Died:Connect() then print("Died") game.ReplicatedStorage:FindFirstChild("StarterToolsOnDeath"):FireServer(char) char.Humanoid:UnequipTools() end
You appear to checking for its connection instead you want to make a function to run when the Died event is ran.
local plr = game.Players.LocalPlayer local char = plr.Character local ReplicatedStorage = game:GetService("ReplicatedStorage") local Attack = ReplicatedStorage:WaitForChild("StarterToolsOnDeath") char:WaitForChild("Humanoid").Died:Connect(function() -- Used WaitForChild("") to hook onto humanoid and made the connect call a function as it doesn't return a bool value. print("Died") game.ReplicatedStorage:FindFirstChild("StarterToolsOnDeath"):FireServer(char) char.Humanoid:UnequipTools() end)