Hello,
I have been trying to write a script for over 1 hour that only allows a special team to spawn a car, for example, the police are allowed to spawn police cars but the citizens are not.
This is what my script looks like, I only managed that everyone can spawn the car, but I didn't manage that, for example, only police officers can spawn police cars.
here my code:
script.Parent.MouseButton1Click: Connect (function (GetCar) Mod = game.ServerStorage.VWPassat clone = Mod: Clone () clone.Parent = workspace clone: MakeJoints () end)
can anyone tell me how I can manage that, for example, police officers can spawn the VW Passat and all other teams cannot?
regards
alright so 3 things you need to do. 1) create a local script in the textbutton on the GUI. 2) create a remoteEvent in ReplicatedStorage name it as you wish. 3) create a script in serverScriptService
the localscript in with as parent the textButton
local rep = game:GetService("ReplicatedStorage") local event = rep:FindFirstChild("YourEvent")--your RemoteEvent script.Parent.MouseButton1Click:Connect(function() local plr = game.Players.LocalPlayer event:FireServer(plr) end)
script in ServerScriptService
local rep = game:GetService("ReplicatedStorage") local event = rep:FindFirstChild("YourEvent") --your RemoteEvent local function CreateCar(plr) if plr.TeamColor == BrickColor.new("White")-- your team color then local clone = game.ServerStorage:WaitForChild("VWPassat"):Clone() clone.Parent = game.Workspace clone:MakeJoints() else print("Not on the correct team")-- if you want an error message or something do it here end end event.OnServerEvent:Connect(CreateCar)