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!
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!
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:
Yeah, but players can still walk through the car… How can I fix that?
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
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
BasePart and MeshPart are not the same
When I use BasePart, nothing happens, it doesn’t change anything
That’s bizzare, MeshParts fall under BaseParts
make sure you set the “Cars” collision group to car parts or it wont work
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?
It could be running before the character actually loads in,so when it gets decendants the character still has no instances in it
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…
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?
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)
…
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)
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
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")
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)