I made this script to automatically remove a player’s tool when they step in a zone. However, if the player has the tool equipped and they walk into the zone, the tool will stay in their inventory.
How would I be able to remove the player’s tool even when it’s equipped?
Code:
workspace.SwordFightParts.RemoveSword.Touched:Connect(function()
if plr.Backpack:FindFirstChild("Sword") then
plr.Backpack.Sword:Destroy()
end
end)
hmm so you want to put it in a normal script… I think? And then when u do delete the player variable and do the (function(plr), lmk if there is errors in output.
also put the serverscript inside the part or in serverscriptservice, if its in the part you can do script.Parent.Touched:Connect(function(plr)
If the tool is equipped when the Touched event is fired, the tool would be inside the Character due to it being equipped. To deal with this, you should check if the tool can be found inside the character if not found in the backpack.
hm ok so i know what it is… So when you touch the brick, its a body part right, so its searching for the backpack inside the part (ex. lets say the leg touches the part it will search for the backpack inside the leg)
part.touched:connect(function(plr)
if plr.Parent:FindFirstChild("Humanoid") then
if plr.Parent:FindFirstChild("Yourtool") then
plr.Parent.YourTool:Destroy()
end
end
end)
When the Touched event is fired, the function would return a part, it’s up to you to determine if that part is a body part, and what player that body part belongs to. After you get the player who touched the part, you can run checks to determine if a sword is found in either the backpack or the character, and remove them.
Because tools go into the player’s character when equipped you could check if it’s in their character and delete appropriately
workspace.SwordFightParts.RemoveSword.Touched:Connect(function()
if plr.Backpack:FindFirstChild("Sword") then
plr.Backpack.Sword:Destroy()
elseif plr.Character:FindFirstChild("Sword") then
plr.Character.Sword:Destroy()
end
end)