kirda

2

Mar 3rd, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.26 KB | None | 0 0
  1. local rep = game:GetService("ReplicatedStorage")
  2. local ServerStorage = game:GetService("ServerStorage")
  3. local Players = game:GetService("Players")
  4.  
  5. local event = rep.VWPassat -- your RemoteEvent
  6.  
  7. local Cars = {}
  8.  
  9. local function CreateCar(plr, Model)
  10.     if Cars[plr.UserId][Model] then
  11.         print("User has already spawned car of brand " .. Model)
  12.     end
  13.    
  14.     if plr.TeamColor == BrickColor.new("Really blue") then
  15.         local clone = ServerStorage.VWPassat:Clone()
  16.         clone.Parent = workspace
  17.         clone:MakeJoints()
  18.        
  19.         -- This will add car to the user cars table with key as the car's name
  20.         Cars[plr.UserId][Model] = clone
  21.     else
  22.         print("Not on the correct team")
  23.     end
  24. end
  25.  
  26. local function RemoveCar(Client, Model)
  27.     if Client then
  28.         local Car = Cars[Client.UserId][Model]
  29.        
  30.         if Car then
  31.             Cars[Client.UserId][Model] = nil
  32.             Car:Destroy()
  33.         end
  34.     end
  35. end
  36.  
  37. local function OnClientAdded(Client)
  38.     -- This will create table of cars for the newly joined gamer, that way
  39.     -- you can store multiple cars of different brands inside of it
  40.     Cars[Client.UserId] = {}
  41. end
  42.  
  43. local function OnClientRemoving(Client)
  44.     RemoveCar(Client)
  45. end
  46.  
  47. Players.PlayerAdded:Connect(OnClientAdded)
  48. Players.PlayerRemoving:Connect(OnClientRemoving)
  49. event.OnServerEvent:Connect(CreateCar)
Advertisement
Add Comment
Please, Sign In to add comment