Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How to disable Tool Collisions?

Asked by 4 days ago

How would I disable tool collisions without making it fall into the void? I want it so that parts of the tool don't collide or get stuck with anything. Because if you could see in this game which is mine, the tools are not handling very well. I mostly get complains wherein the guns get stuck within the walls.

2 answers

Log in to vote
1
Answered by
Elyzzia 1023 Moderation Voter
4 days ago
Edited 4 days ago

rather than trying to make the tools completely uncollidable, you could try making them uncollidable when a player is holding them, but collidable otherwise

local tool = script.Parent
local Players = game:GetService("Players")

-- scripts don't run when they're in the player's backpack so you have to check if the tool is already owned by a player when it gets re-parented, or else it might fall into the void

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) -- not gives you the opposite of a value's truthiness, so using not here is like saying "if there's an owner, then set CanCollide to false"

tool.Equipped:Connect(function()
    setCollidability(false)
end)

tool.Unequipped:Connect(function()
    setCollidability(true)
end)

if you want some parts to ALWAYS be uncollidable then you could iterate over descendants of the tool and give them an "OriginalCollidability" value, where if it's false the part will always be uncollidable and if it's true its collidability will be able to change

you could also use collision groups and just set the part's collision group beforehand, which does the work for you

0
thx elyzzia you're the best i hope u still remmeber me from server w xxIamInevitable 2 — 3d
Ad
Log in to vote
-1
Answered by 4 days ago
local PhysicsService = game:GetService("PhysicsService")

local defaultGroup = PhysicsService:GetCollisionGroupName(0);
local playerGroup = "PlayerGroup";
local npcGroup = "NPCGroup";

PhysicsService:CreateCollisionGroup(playerGroup);
PhysicsService:CreateCollisionGroup(npcGroup);

function setNPCGroup(char)
    for i,v in pairs(char:GetDescendants()) do
        if (v:IsA("BasePart")) then
            PhysicsService:SetPartCollisionGroup(v, npcGroup);
        end
    end
end

function setPlayerGroup(char)
    for i,v in pairs(char:GetDescendants()) do
        if (v:IsA("BasePart")) then
            PhysicsService:SetPartCollisionGroup(v, playerGroup);
        end
    end
end

This can disable colliding between npc and players.

Answer this question