So, I’ve been trying to make a better script to detects when a tool is removed from player completely(Backpack and Character).
If there’s any better method than this, please let me know. I just feel my script is messy and I’m pretty sure there’s a better way to do this…
- The script:
local Player = script.Parent.Parent
local Backpack = script.Parent
local Character = game.Workspace:WaitForChild(Player.Name)
local Equipped = false
Backpack.ChildRemoved:Connect(function(tool)
tool.Equipped:Connect(function()
Equipped = true
end)
tool.Unequipped:Connect(function()
Equipped = false
end)
if tool:FindFirstChild("Weapon") then
wait(0.5)
if tool.Parent ~= Character or tool.Parent ~= Backpack and Equipped == false then
for i,v in pairs(Character:GetChildren()) do
if v:IsA("Model") and v.Name == tool.Name then
v:Destroy()
end
end
end
end
end)
Tool is in Backpack, there’s completely no issues with it I just wanna know if there’s any better methods to do this.
EDIT: In update of this situation, I found a better way to do this in my game when the player gets rid of a tool.