I am trying to make the tool in a user's hand delete from the character and also from starter gear. However, it only deletes from the character and not from starter gear. Below is inside a local script under an image button. Why is this happening?
local function onCreatePartFired(player, tool) local SG = player.StarterGear if tool then tool:Destroy() end if SG:FindFirstChild(tool.Name) then print("hey") SG[tool.Name]:Destroy() end end local Players = game:GetService("Players") plr = game:GetService("Players").LocalPlayer char = plr.Character or plr.CharacterAdded:Wait() script.Parent.MouseButton1Click:Connect(function() local tool = char:FindFirstChildOfClass("Tool") onCreatePartFired(plr,tool) end)
If "tool" exists, then the second if block will never run because you'll destroy the tool before being able to access its name. Try:
local function onCreatePartFired(player, tool) local SG = player.StarterGear if tool then local sg_tool = SG:FindFirstChild(tool.Name) if sg_tool then print("hey") sg_tool:Destroy() end tool:Destroy() end end