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?
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.
…? 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.
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
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.
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.
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.