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

How to turn off collide between part and player?

Asked by 3 years ago

I need to disable collision between player and part, but the only thing I know is how to disable collision for everything, this is not what I need.

The thing is, I have a script to grab a part, but the problem is that the player can jump on it and fly.

If use my script, then part can go through walls and floor for a while after touching the player.

How to turn off collide between part and player?

My script:

local function PlayerTouched(Part)
    if game.Players:GetPlayerFromCharacter(Part.Parent) then
        script.Parent.CanCollide = false
    else
        script.Parent.CanCollide = true
    end
end

script.Parent.Touched:connect(PlayerTouched)

2 answers

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

You can make a local script and make the part nocollided on the client while the script is grabbing the part and then make it collide once its done grabbing the part

script.Parent.CanCollide = false
wait(10) -- put however many seconds it takes to grab the part
script.Parent.CanCollide = true

Put the localscript in the part and you can add onto this script to make it activate once its starting to grab the part.

This is a simple fix that should work. There is also other ways to do that.

Hope this helps. - Zeta

Ad
Log in to vote
0
Answered by 3 years ago

Solution turned out to be much easier than I thought. I used "Collision Groups" in the top "Model" tab. There I created 2 groups: the first one I called "One", and the second - "Two". For the second group, I unchecked the "One" column.

And it remains to write a little code (I paste this in the grab local script):

local PS = game:GetService("PhysicsService")
local character = game.Players.LocalPlayer.Character

--When player grab a part
    PS:SetPartCollisionGroup(character.HumanoidRootPart,"One")
    PS:SetPartCollisionGroup(character.UpperTorso,"One")
    PS:SetPartCollisionGroup(character.LowerTorso,"One")
    PS:SetPartCollisionGroup(character.Head,"One")
--When player stop grab a part
    PS:SetPartCollisionGroup(character.HumanoidRootPart,"Two")
    PS:SetPartCollisionGroup(character.UpperTorso,"Two")
    PS:SetPartCollisionGroup(character.LowerTorso,"Two")
    PS:SetPartCollisionGroup(character.Head,"Two")

And for part you need create this script:

local PS = game:GetService("PhysicsService")
PS:SetPartCollisionGroup(script.Parent,"One")

Thus, when player grab a part, his collision group for the main body parts becomes same as that of the part, and he cannot jump on it, and when he releases part, collision group becomes "Two" and player can again interact with part.

Anyway, thank you all for your help.

Answer this question