Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this script make the tool collidable for a second?

Asked by
TechModel 118
3 years ago

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)
0
If you set everything in the tool to CanCollide: true but when you equip the tool, the handle automatically gets CanCollide: false. I re-edited my post check it out MarkedTomato 810 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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)
0
But then if I drop the tool, it then just swings on the floor? TechModel 118 — 3y
0
Also don't anchor anything in the tool MarkedTomato 810 — 3y
Ad

Answer this question