HowToRoblox

CarSpawner

Sep 21st, 2021
780
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local plrCars = {}
  2.  
  3.  
  4. game.ReplicatedStorage:WaitForChild("CarSpawnRE").OnServerEvent:Connect(function(plr, car)
  5.    
  6.     if car then
  7.        
  8.         if plrCars[plr] then
  9.            
  10.             plrCars[plr]:Destroy()
  11.         end
  12.        
  13.        
  14.         local newCar = car:Clone() 
  15.        
  16.         local hrp = plr.Character.HumanoidRootPart
  17.        
  18.         newCar:SetPrimaryPartCFrame(hrp.CFrame + (hrp.CFrame.LookVector * 10) + Vector3.new(0, 10, 0))
  19.        
  20.         newCar.Parent = workspace
  21.        
  22.         plrCars[plr] = newCar
  23.     end
  24. end)
RAW Paste Data