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

Making CanCollide false for Players when they touch other Players?

Asked by 8 years ago

So basically I have this script where it makes players able to walk through parts and stuff. However this is inconvenient because the game i'm making is a sort of obby course and if players can just walk through all the walls it would be too simple. My scripting knowledge is still rather basic so I have no idea how to do this, but I was wondering if anyone has a way of making it so that players can only walk through each other and still collide on things like parts. This is the code I have at the moment:

local player = game.Players.LocalPlayer

function Touched(hit)
    if hit.Locked == false then
    hit.CanCollide = false
    end
end

function TouchEnded(hit)
    if hit.Locked == false then
    hit.CanCollide = true
    end
end

player.CharacterAdded:connect(function(character)
character.Head.Touched:connect(Touched)
character.Head.TouchEnded:connect(TouchEnded)
character.Torso.Touched:connect(Touched)
character.Torso.TouchEnded:connect(TouchEnded)
character["Left arm"].Touched:connect(Touched)
character["Left arm"].TouchEnded:connect(TouchEnded)
character["Right arm"].Touched:connect(Touched)
character["Right arm"].TouchEnded:connect(TouchEnded)
character["Left leg"].Touched:connect(Touched)
character["Left leg"].TouchEnded:connect(TouchEnded)
character["Right leg"].Touched:connect(Touched)
character["Right leg"].TouchEnded:connect(TouchEnded)
end)

^ I put that in a Local Script and placed it inside StarterPack, which worked. It's just that I need it to allow players to walk through each other and not through parts (because the obby i'm making is extremely challenging and it would suck if players could affect the progress of others by blocking paths off etc)

Thanks for any help/advice

~ MrTurkeys

2 answers

Log in to vote
1
Answered by
3tianne 20
8 years ago

Your best bet is probably to set CanCollide = false on all of the players' parts whenever they collide and use a BodyForce to keep them from falling through the map.

0
How would I go about doing that? Would I use an PlayerAdded function or something? MrTurkeys 10 — 8y
0
You could just connect the body force in the torso using the PlayerAdded event. yougottols1 420 — 8y
0
No, because you only want the BodyForce to be inside the Torso when the player's parts have CanCollide set to false. Use the Touched event on the HumanoidRootPart and connect it to a function that sets CanCollide to false on all of the player's parts and inserts a BodyForce into the Torso to counteract gravity. 3tianne 20 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

To set your torso and head's CanCollideto False, you need to make a loop.

I do not feel like making the script for you since it wouldn't really be helping you, it would be doing the whole job for you, but for the cancollide script, use this:

game:GetService("RunService").stepped:connect(function()
    game.Players.LocalPlayer.Character.Torso.CanCollide=false
    game.Players.LocalPlayer.Character.Head.CanCollide=false
end)

Answer this question