Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How do i get it for when something from the player gets removed it prints?

Asked by 9 years ago

I was wondering how i would get something to print when something from the players character gets removed i.e Hats. I have tried using the changed event but it does not do it. Here is something i have tried.

game.Players.PlayerAdded:connect(function(player)
    game.Workspace:FindFirstChild(player.Name).Changed:connect(function(Chang)
        --Stuff
    end
end

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

The Changed events only fires when an Object's properties change. To catch children being removed, use the DescendantRemoving event.

Additionally, your code will only catch changes on the player's first Character: it won't work if they respawn. To fix that, we use the CharacterAdded Event of Player objects:

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character.DescendantRemoving:connect(function(obj)
            print(obj.Name)
        end)
    end)
end)
0
Thanks. :D raspyjessie 117 — 9y
Ad

Answer this question