Im trying to make the player’s body parts non collideable while there’s a body velocity inside the player’s humanoid root part
local bv = Instance.new("BodyVelocity", hrp)
bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bv.Velocity = hrp.CFrame.LookVector * 200
local ghostPlayer = coroutine.create(function()
while wait() and hrp:FindFirstChild("BodyVelocity") do
for i, v in pairs(char:GetChildren()) do
if v:IsA("BasePart") then
v.CanCollide = false
end
end
end
end)
coroutine.resume(ghostPlayer)
wait(0.3)
bv:Destroy()
Do you just want the ghost player to not collide with other players, or do you want it truly to collide with nothing? Either way the answer lies with collision groups in PhysicsService. You can assign objects to separate groups and then set the groups to not be collidable with each other, or even not collidable with themselves.
You can use PhysicsService to change the collision group of all of the player’s parts.
local PhysicsService = game:GetService("PhysicsService")
PhysicsService:CreateCollisionGroup("Ghost")
PhysicsService:CollisionGroupSetCollidable("Default", "Ghost", false)
PhysicsService:CollisionGroupSetCollidable("Ghost", "Ghost", false)
local function ghostPlayer(player)
for index, part in pairs(player.Character:GetDescendants()) do
if part:IsA("BasePart") then
PhysicsService:SetPartCollisionGroup(part, "Ghost")
end
end
end
-- to unghost, do the same thing just with the 'Default' group
This will make the player collide with absolutely nothing, including the ground they’re standing on. If you want the player to only be able to phase through selective parts such as walls, you would need to create a new CollisionGroup and assign all of those parts to the group. If this is the approach you want, I would suggest using CollectionService paired with Tiffany’s Tag Editor to make it easier to select the parts you want the player to be able to phase through.
local PS = game:GetService("PhysicsService")
PS:CreateCollisionGroup("Player")
PS:CreateCollisionGroup("Ghost")
PS:CollisionGroupSetCollidable("Player", "Ghost", false)
PS:CollisionGroupSetCollidable("Default", "Ghost", true)
PS:CollisionGroupSetCollidable("Default", "Player", true)
PS:CollisionGroupSetCollidable("Player", "Player", true)
---------------------------------------------------------------------
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
for i, v in pairs(char:GetChildren()) do
if v:IsA("BasePart") then
PS:SetPartCollisionGroup(v, "Player")
end
end
end)
end)
then when i put a player’s body parts inside the Ghost group it won’t collide with player but it will with default stuff?