/vehices command

Hello dev forum! I would like to make a new command. The command is /vehices and if a supervisor+ does this they get a GUI and they can click “spawn (car name)”. Now unlike some spawners the car would not spawn in one spot it would spawn were they are standing,

My issue is I have no clue how to make this.

I have looked this up on youtube but nothing.

Can you help?

First I would start with a simple command script, you can create one by following this tutorial, it allows you to choose who you want to be able to do the command. I would then make it so your GUI is visible after this command is executed. Lastly, I would duplicate the vehicle from where ever you’re keeping it and set its position to be near the player.
Hope this helps!

Ok… I am not to sure how you set its position to be near the player and I have no clue how to script so the tutorial is kinda hard.

Alright, I’ll put together a short tutorial on how to do it (I’m going to use a part instead of a vehicle). As for how to put it in front of character it is shown here. I’ll get back to you with the tutorial soon!

This is what you will achieve from my short tutorial:
https://gyazo.com/c5f9c28f79c245ce8abe992772e6f615
Instead of a vehicle I’m using a part!

I would begin with a script in server script service that looks like this (I would highly recommend you read all of the notes to get and understanding of what happens):

local Prefix = "/"

game.Players.PlayerAdded:Connect(function(plr) --checks if player joins
	plr.Chatted:Connect(function(msg) --checks if player talks
		if plr:GetRankInGroup("YOUR GROUP RANK HERE") == "the number here" then --replace with group id and rank number
			local loweredString = string.lower(msg) --converts the message to lowercase
			local args = string.split(loweredString," ") --splits between spaces
			if args[1] == Prefix.."YOUR COMMAND" then --checks if the first word of the command is your command
				plr.PlayerGui.vehicleFrame.Enabled = true --enables the GUI
			end
		end
	end)
end)

For that I basically used this tutorial.
Next in the local script of the part adding button I inserted a local script. The code should looks something like this:

local plr = game.Players.LocalPlayer --gets player
local char = plr.Character or plr.CharacterAdded:Wait() --gets character

local button = plr.PlayerGui.vehicleFrame.spawnPart --gets button

button.MouseButton1Up:Connect(function() --checks if button is clicked
	local part = Instance.new("Part") --creates new part
	part.Parent = workspace --puts part into workspace
	part.Position = char.HumanoidRootPart.Position + char.HumanoidRootPart.CFrame.LookVector * 10 --moves part in front of character
end)

Of course you have to edit the scripts to get your result, but I hope it helps!

Hi just say this now. This looks great and I will be editing it to my liking. So I put the first script in serverscriptstorage and then second one in starterplayerscripts?

That definitely works, but instead of editing the player’s GUI stuff from the server, I’d recommend using remote events.

Yep, or you could put it in the starter gui. Make sure you have made the GUI elements and named it exactly like they did.

local players = game:GetService("Players")
local server = game:GetService("ServerStorage")
local vehicleGui = server.VehicleGui --Example vehicle gui.

local groupId = 0 --Change to ID of group.
local groupRank = 0 --Change to required group rank.

players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if message:lower():match("^/vehicles") then
			local success1, result1 = pcall(function()
				return player:IsInGroup(groupId)
			end)
			
			if success1 then
				if result1 then
					print(result1)
					local success2, result2 = pcall(function()
						return player:GetRankInGroup(groupId)
					end)
					
					if success2 then
						if result2 then
							print(result2)
							if result2 >= groupRank then
								vehicleGui:Clone().Parent = player.PlayerGui --Clone gui into player's "PlayerGui" folder.
								--Other code here.
							end
						end
					else
						warn(result2)
					end
				end
			else
				warn(result1)
			end
		end
	end)
end)

Here’s a script which will clone a “ScreenGui” instance into a player’s “PlayerGui” folder when that player chats “/vehicles” and meets the group rank requirement.

On an additional note this implementation will also allow you to abbreviate the command to “/v” or “/veh” etc.

Would this go in server script storage?

The script would go in ServerScriptService, the gui you want cloned and parented into the player’s “PlayerGui” folder would go in ServerStorage.

Ok so the script pretty much works but the cars are not spawning next to the player they are only spawning in one spot/

Well the script I provided shouldn’t be spawning any vehicles, unless you added that in somewhere.

Well your command works great! I am trying to have the UI when you click sawn vehicles but they are spawning in one spot not next to the player.

I’d recommend starting a new thread for assistance with that.

I put that in this thread. I said that I need the car to spawn where they are standing.

You’ll need to share the gui script which is spawning vehicles. Without that I’m not sure how you expect us to help.

This is the “SpawnCV” script

script.Parent.MouseButton1Click:connect(function(GetCar)
Mod = game.ServerStorage.CrownVic --Change test to whatever you have named the item you want to spawn
clone = Mod:clone()
clone.Parent = workspace
clone:MakeJoints()
end)

local player = script:FindFirstAncestorOfClass("Player")
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")

script.Parent.MouseButton1Click:connect(function(GetCar)
	Mod = game.ServerStorage.CrownVic --Change test to whatever you have named the item you want to spawn
	clone = Mod:clone()
	clone:PivotTo(hrp.CFrame * CFrame.new(0, 5, -5))
	clone.Parent = workspace
	clone:MakeJoints()
end)

CFrame.new(0, 5, -5)

You may need to change this bit.

Thank you so much Forummer. This has helped me alot.

1 Like