How do I make it so this car spawning script triggers whenever a player says a command

Ok that works, but how do I get it to spawn next to the player?
Also don’t forget that I wanted it so that only certain players can use the command.

Either one; use a vector such as a Look vector, then multiply that.

Car:SetPrimaryPartCFrame(CFrame.new(Character.HumanoidRootPart.LookVector * 5))

Or 2, get the character position, and add it by a certain vector.
example:

Car:SetPrimaryPartCFrame(CFrame.new(Character.HumanoidRootPart.Position + Vector3.new(5, 0, 0)))

I’ll revamp the code to your liking rq; you can read it over to understand it.

task.wait()
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Command = "/spawn"

local Main = {
   ["cars"] = {
      ["sCar"] = ServerStorage:WaitForChild("") -- Input your directory.
   };

   ["Whitelisted_UserId"] = {
      1, -- Roblox
      2 -- John doe
   }
}

local function GetCharacter(plr : Instance)
   local character = plr.Character
   if character then
      return character
   end
end

game.Players.PlayerAdded:Connect(function(plr)
    for _, g in pairs(Main.Whitelisted_UserId) do
       if plr.UserId == g then
          plr.Chatted:Connect(function(msg)
          local args = string.split(msg, " ")
              if string.lower(args[1]) == Command then
                 for n, v in next, Main.cars do
                    if string.lower(args[2]) == n then
                       local Car = v:Clone()
                       if Car then
                          local Character = GetCharacter(plr)
                          Car.Name = plr.Name .. n
                          Car.Parent = game.Workspace
                          if Character then
                             if Character:FindFirstChild("HumanoidRootPart") then
                                Car:SetPrimaryPartCFrame(CFrame.new(Vector3.new(Character.HumanoidRootPart.LookVector * 5)))
                             end
                          end
                       end
                    end
                 end
              end
          end)
       end
    end
end)

The car will spawn above the player while trying that.

Which method are you using, if adding vectors, what’s the vector that is adding the other?
If a lookvector or so, what is it being multiplied by?

The adding vectors method. The vector that’s adding the other is 5.

Are you doing:

Vector3.new(0, 5, 0)

?

If so, you are actually adding the Y axis (5) which puts the car above the players head.
Try another vector like:

Vector3.new(10, 0, 0)

If this is not the case, please send the little snippet of you adding the vectors.

Changing the vector works! Anyways time to head off to build my game now.

Got a output when I tried adding multiple cars.

Yes, you will have to be required to set a PrimaryPart.
You have not set a Primary part for a specific car (or others).
Change the “PrimaryPart” for the car model, and set it to a specific part. (Usually you would put it in the middle part of the model).