Player is not a Humanoid instance, therefore it cannot “die”. Instead, use this instead.
local humanoid
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
humanoid = character:WaitForChild("Humanoid")
end)
end)
You put the variable before anything else, and then define it when the player’s character is added and the humanoid is found. You can then proceed to use the humanoid anywhere else like as if it were a global variable.
humanoid.Died:Connect(function()
--Died event here
end)
If you are confused, let me sum it up here.
While you defined the variable “Player” as LocalPlayer, you however did not define it as character, nor a humanoid. And since it is not a humanoid instance it therefore does not have a “Died” event. What you should do in order to be able to use the local variable anywhere else is define the variable at the start of the script, give it its value as the humanoid when the character is added (like shown above), and then you can proceed to do anything else.
I would also like to let you know that I don’t think there is a Player.Alive event or a “when” statement. I think this is what you want.
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
script.Parent = character
humanoid.Died:Connect(function()
for _, item in ipairs(character:GetChildren()) do
if item:IsA("ObjectValue") then --replace objectvalue with what the value is
item:Destroy()
else
print("Player has no items!")
end
end
end)
Basically what I did up there was get the local player, then get the character of it or wait for it, then wait for the humanoid. If you don’t know why, it’s because when a player joins a game (it also depends on their internet connection) most of the time certain parts of their character haven’t even loaded, which is why we use the method :WaitForChild to wait for the humanoid. It yields the whole thread like the regular wait(), and the whole script won’t run until it has found the humanoid.
The next thing I did up there was use the humanoid.Died event. Wherein I ran a loop through the player’s character to see if there were any ObjectValues (or whatever they are). If the item was an ObjectValue, they would then be destroyed.
Let me know if I helped!