How do I made fix this script to make it can collide false when the tool's equipped? But when I take the tool out it makes if collidable for a second, which I don't want that. If there's a way to make it can collide false when in the players backpack and when it is dropped, it is collidable so the tool doesnt swing on the floor. The script's location is parented in the tool. The reason I have it is to use the tool without interfearance in the games object world, for instance, taking out the tool when your character facing flat on the wall, and it either pushes the character back or trips it, and I don't want that.
local tool = script.Parent local Players = game:GetService("Players") local function setCollidability(collidability) for _, descendant in pairs(tool:GetDescendants()) do if descendant:IsA("BasePart") then descendant.CanCollide = collidability end end end local owner = Players:GetPlayerFromCharacter(tool.Parent) setCollidability(not owner) tool.Equipped:Connect(function() setCollidability(false) end) tool.Unequipped:Connect(function() setCollidability(true) end)
I don't think you need to do this. Just unanchor all the BaseParts in the tool, and turn CanCollide false for all BaseParts within the tool. CanCollide: false is optional if you want your tool to go through walls but otherwise, you don't.
Note: Tools in StarterPack get cloned and the cloned tools get moved into the player's backpack located in Players > [Player's name] > Backpack. When equipping a tool, the tool will be moved into the player's character model. Unequiping a tool moves it back to the player's backpack.
Every service in the explorer named with 'Starter' always replicates something to the client. Solution:
local tool = script.Parent tool.Equipped:Connect(function() for index, basepart in pairs(tool:GetDescendants()) do if basepart:IsA("BasePart") then basepart.CanCollide = false end end end) tool.Unequipped:Connect(function() tool.Handle.CanCollide = true end)