Hello, I encountered a bug that is not very clear to me… My Character
is holding a Tool
or this Tool
is in the player’s Backpack
, I am trying to destroy the Character
(from the server side), he is successfully destroyed via Destroy
method, but the Tool
continues to be displayed in my inventory. What is this related to and how can it be fixed? Help me please…
1 Like
Hi I will be able to help you with this. The issue is you are describing two different scenarios. Are you wanting the tool to be destroyed while the character is holding the tool? Are you wanting it to be destroyed while it’s in the player’s backpack? or do you want it to be destroyed in both scenarios?
it need to be destroyed in both scenarios
Try destroying the tool in the player’s backpack.
I think so too, if it can’t be solved in other ways
--Works
workspace.DescendantRemoving:Connect(function(desc)
for i, v in pairs(game.Players:GetPlayers()) do
if v.Name == desc.Name then
if v.Backpack:FindFirstChildOfClass("Tool") then
v.Backpack:FindFirstChildOfClass("Tool"):Destroy()
end
end
end
end)
--Also works
local Players = game:GetService("Players")
local function onPlayerAdded(player)
player.CharacterAdded:Connect(function(character)
character.Destroying:Once(function()
player.Backpack:ClearAllChildren()
end)
print(player.Name .. " character spawned")
task.wait(2)
character:Destroy() --you can call this anywhere this is just for demonstration
end)
player.CharacterRemoving:Connect(function(character)
print(player.Name .. " character is being removed")
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
Simple as that
Character.Destroying:Once(function()
Plr.Backpack:ClearAllChildren()
end)
or
Character.Destroying:Wait()
Plr.Backpack:ClearAllChildren()
1 Like