Needing help with a GroupID rank Vehicle Spawner

Hello ROBLOX Developers!

As you can see, my name is Cenosity! I am a Terrain Developer on here. Brand-new to the DevForum community, but I don’t want to come in as if I shouldn’t be here. I am having a problem coming up with the right-way to make a car-spawner only allow a certain rank, per groupID spawn. Thus, I have provided images of everything setup, and the script I currently have, to see if anyone could help me improve off of it?

I know there are several ways for me to go about doing this, but I believe this vehicle-spawner will work best for what I am configuring it for.

How would I add a groupID only spawner to this? Specifically per rank, via. player:GetRoleInGroup(4056177) >= 255

Script

script.Parent.MouseButton1Click:connect(function(GetCar)
		Mod = game.ServerStorage.mc -- Pulling the Vehicle Out of the ServerStorage
		clone = Mod:clone()
		clone.Parent = workspace
		clone:MakeJoints()
end)

This script pulls the vehicle out of the ServerStorage, and spawns it, now I need help making it group only?

ANYTHING WILL HELP!
-Cenosity

1 Like

GetRoleInGroup returns a String, which is the name of the role. You’re looking for GetRankInGroup, which returns an integer (which is their rank id).


Also on a side note I can spam click that button as a player so you should either add a debounce or check if a vehicle is already spawned.

3 Likes

No. I was looking for the feedback you gave me, and am not trying to solve the issue with the feedback. I didn’t know what to look for, but you directed me in the right direction.

I explained how to solve the problem, using a suggestion you provided. Are you trying to look for someone to script this for you then?

…? It looks like you already know the answer to the problem, aside from a minor mistake in the word used in the function?

In either case, your code raises some eyebrows. Judging from the event being connected to (MouseButton1Click), I assume you’re using a Gui and not a ClickDetector. Guis should be handled by LocalScripts, which do not have access to ServerStorage - therefore, this interaction should be facilitated by a remote.

  • The client connects to MouseButton1Click
  • The client fires a remote asking for a car spawn
  • The server connects to the remote’s OnServerEvent
  • The server checks if the player is above a certain rank, amongst other checks, before spawning a car or rejecting the request (by doing nothing)

Another note - MouseButton1Click doesn’t pass any arguments. The GetCar in the parenthesis is unnecessary and it’ll be nil as well.

3 Likes

I have created the scripts for you.
Put this LocalScript inside the TextButton:

local GroupId = 12345 -- Put the GroupId here
local Cooldown = 2 -- Put the cooldown time here
local GroupRanks = {255,200} -- Put the group ranks in here that you want to be able to spawn the car


local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local debounce = false

script.Parent.MouseButton1Click:connect(function()
	if debounce == false then
		debounce = true
		for i,v in pairs(GroupRanks) do
			if Players.LocalPlayer:GetRankInGroup(GroupId) == v then  -- Checks if the player is able to spawn the vehicle 
				ReplicatedStorage.RemoteEvent:FireServer()
				wait(Cooldown)
				Cooldown = false
			else
				wait(Cooldown)
				debounce = false
			end
		end
	end
end)

Put this Script in ServerScriptService:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

ReplicatedStorage:WaitForChild("RemoteEvent").OnServerEvent:Connect(function()
	local Mod = game.ServerStorage.mc 
	local clone = Mod:clone()
	clone.Parent = workspace
	clone:MakeJoints()
	
end)

Then put a RemoteEvent in ReplicatedStorage named RemoteEvent

4 Likes

I didn’t mean for someone to do this for me, but I value the time you’ve spent to configure this system.

Thank-you very-much! I did try a few things, and they put together to work, but this is more complex, and will provide a lot better.

Glad to see people like you able to help us newcomers out :slight_smile:

-Ceno

1 Like

You should probably mark the correct answer given above so people don’t keep checking on this because they don’t see that it is marked as solved.

3 Likes

Thank you, it means a lot! Be warned that the code that I provided isn’t optimised to stop exploiters spamming it but it is stops normal players from spamming it. As exploiters can access the clients code. That is a completely different thing to what your issue is.

1 Like

Is it to be used with a clickdetector, or a textbutton?

1 Like

TextButton

1 Like

Oh huh, because it wasn’t working, no errors, but didn’t spawn :man_shrugging:

Things you may be doing wrong:

  • Have you put a RemoteEvent in ReplicatedStorage?

  • Is a LocalScript inside the TextButton not a script?

Valid. I have found a solution to this issue as of now.

What was it so the rest of know if we have the same problem.

3 Likes

His did not end up working.

local ClickDetector = script.Parent.ClickDetector
local UI = script.Parent.Spawn
local GroupID = "4056177"
local Rank = 200
local Delay = 5

local Debounce = false

ClickDetector.MouseClick:Connect(function(Player)
    if (Player:GetRankInGroup(GroupID) >= Rank) and not Debounce then
	   Debounce = false
       UI.Enabled = false
       local clone = game.ServerStorage.AdminTahoe:Clone()
       clone.Parent = workspace
       clone:MakeJoints()
       wait(Delay)
       Debounce = true
       UI.Enabled = true
    end
end)

I ended up doing it this way, and with a ClickDetector. Using it with a textbutton, did not spawn the vehicle.

1 Like

Most likely because you did it wrongly. TextButtons are still viable for vehicle spawning, provided you’re working with an interface and include proper networking.

1 Like