Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local rep = game:GetService("ReplicatedStorage")
- local ServerStorage = game:GetService("ServerStorage")
- local Players = game:GetService("Players")
- local event = rep.VWPassat -- your RemoteEvent
- local Cars = {}
- local function CreateCar(plr, Model)
- if Cars[plr.UserId][Model] then
- print("User has already spawned car of brand " .. Model)
- end
- if plr.TeamColor == BrickColor.new("Really blue") then
- local clone = ServerStorage.VWPassat:Clone()
- clone.Parent = workspace
- clone:MakeJoints()
- -- This will add car to the user cars table with key as the car's name
- Cars[plr.UserId][Model] = clone
- else
- print("Not on the correct team")
- end
- end
- local function RemoveCar(Client, Model)
- if Client then
- local Car = Cars[Client.UserId][Model]
- if Car then
- Cars[Client.UserId][Model] = nil
- Car:Destroy()
- end
- end
- end
- local function OnClientAdded(Client)
- -- This will create table of cars for the newly joined gamer, that way
- -- you can store multiple cars of different brands inside of it
- Cars[Client.UserId] = {}
- end
- local function OnClientRemoving(Client)
- RemoveCar(Client)
- end
- Players.PlayerAdded:Connect(OnClientAdded)
- Players.PlayerRemoving:Connect(OnClientRemoving)
- event.OnServerEvent:Connect(CreateCar)
Advertisement
Add Comment
Please, Sign In to add comment