No Clip [Car Help!]

Hello guys!

I am trying to make it so that the player has to press “E” to enter the vehicle, rather than walking through.
… and yes, I tried enabling Can Collide, but the car just didn’t move…

Thanks!

3 Likes

Proximity prompts, Disable the car seat so players can’t get into it by walking into it

local proximityPrompt= --Just get a reference to your proximity prompt here
local seat= --The seat you're gonna have to enable later in the script

proximityPrompt.Trigerred:Connect(function(player)
local character=player.Character
if not character then return end --Just incase, likely not needed
seat.Disabled=false
seat:Sit(character.Humanoid)
end)

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if seat.Occupant then return end --Player got in by the prompt
seat.Disabled=true
end)

Link to the documentation of proximity prompts:

2 Likes

Yeah, but players can still walk through the car… How can I fix that?

1 Like

You can use collisiongroups to make only a select of objects to be able to collide/not collide with the said object

local PhysicsService = game:GetService("PhysicsService")
 
-- Create two collision groups
PhysicsService:CreateCollisionGroup("Cars")
PhysicsService:CreateCollisionGroup("Players")

-- Make the groups collide with each other
PhysicsService:CollisionGroupSetCollidable("Cars", "Players", true)

then loop through player’s character and set all their limbs collisiongroup to players like this:

for i,v in pairs(player.Character:GetDescendants()) do
    if v:IsA("BasePart") then
          PhysicsService:SetPartCollisionGroup(v, "Players")
    end
end

do the same for the car but set their collision group to “Cars” instead

2 Likes

I am having issues…

This script is in the character

local player = script.Parent
local PhysicsService = game:GetService("PhysicsService")

for i,v in pairs(player:GetDescendants()) do
	if v:IsA("MeshPart") then
		PhysicsService:SetPartCollisionGroup(v, "Players")
		print("f")
	end
end
1 Like

BasePart and MeshPart are not the same

1 Like

When I use BasePart, nothing happens, it doesn’t change anything

1 Like

That’s bizzare, MeshParts fall under BaseParts

1 Like

make sure you set the “Cars” collision group to car parts or it wont work

1 Like

@uriel_Gamer444 @Frostholl

image

local player = script.Parent
local PhysicsService = game:GetService("PhysicsService")

for i,v in pairs(player:GetDescendants()) do
	if v:IsA("BasePart") then
		PhysicsService:SetPartCollisionGroup(v, "Players")
		print("f")
	end
end

What am I doing wrong?

1 Like

It could be running before the character actually loads in,so when it gets decendants the character still has no instances in it

1 Like

It’s supposed to be a server script, also i’d suggest you use characteradded for that instead of whatever you’re doing right now…

2 Likes

So everything seems to be working… but I can still collide with it… is it something to do with the car’s cancolide being false?

image



local PhysicsService = game:GetService("PhysicsService")
local part = script.Parent

	local function setCollisionGroup(object)
		if object:IsA("BasePart") then
		object.CollisionGroup = "Cars"
	end
	end

local function loopDescendants(parent)
	for _, child in ipairs(parent:GetDescendants()) do
		setCollisionGroup(child)
	end
end

loopDescendants(part)

image

local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")

PhysicsService:RegisterCollisionGroup("Players")
PhysicsService:RegisterCollisionGroup("Cars") --
PhysicsService:CollisionGroupSetCollidable("Cars", "Players", false)

local function onDescendantAdded(descendant)
	if descendant:IsA("BasePart") then
		descendant.CollisionGroup = "Players"
	end
end

local function onCharacterAdded(character)
	for _, descendant in character:GetDescendants() do
		onDescendantAdded(descendant)
	end
	character.DescendantAdded:Connect(onDescendantAdded)
end

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end)
1 Like

@Frostholl @uriel_Gamer444

Ideas?

If your character collides with the car when CanCollide is set to false then something us messed up, But I’m really not sure what you may be doing wrong

run this script on the server

local PhysicsService = game:GetService("PhysicsService")

local function setCollisionGroupForModel(model, collisionGroup)
    for _, descendant in pairs(model:GetDescendants()) do
        if descendant:IsA("BasePart") then
            PhysicsService:SetPartCollisionGroup(descendant, collisionGroup)
        end
    end
end

local function setCollisionGroupForAllPlayers(collisionGroup)
    for _, player in pairs(game.Players:GetPlayers()) do
        local character = player.Character
        if character then
            setCollisionGroupForModel(character, collisionGroup)
        end
    end
end

setCollisionGroupForAllPlayers("Players")

This will run for all players.

I modified your script a bit.

local PhysicsService = game:GetService("PhysicsService")
local part = script.Parent

local function setCollisionGroup(object)
	if object:IsA("BasePart") then
		object.CollisionGroup = "Cars"
	end
end

local function loopDescendants(parent)
	for _, child in ipairs(parent:GetDescendants()) do
		setCollisionGroup(child)
	end
end

loopDescendants(part)

part.DescendantAdded:Connect(function(descendant)
	setCollisionGroup(descendant)
end)