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,
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!
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!
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?
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.
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)