I am trying to make a command that will bring the players vehicle to them, but I can’t get it to work, can somebody please help me with this?
local Vehicles = game.Workspace.Vehicles
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Msg)
if Msg == ":bringcar" then
local PlayerVehicles = Vehicles:GetChildren()
for _, Vehicle in pairs(PlayerVehicles) do
local Control_Values = Vehicle:FindFirstChild("Control_Values")
if Control_Values and Control_Values.Owner.Value == Player.Name then
local PlayerBody = Player.Character
local VehicleModel = Control_Values.Parent
local PlayerRootPart = PlayerBody:FindFirstChild("HumanoidRootPart")
if PlayerRootPart then
local offset = PlayerRootPart.CFrame.Position - VehicleModel.PrimaryPart.Position
VehicleModel:SetPrimaryPartCFrame(VehicleModel.PrimaryPart.CFrame + offset)
end
end
end
end
end)
end)