Hello everyone,
From month I’m trying to make a TeamLock system, so people can join a team only if they have a certain rank. I tried many ways to make it
The first type of code i tried was this, that worked fine with the lock, but when I teammed myself it didn’t let me spawn in the Team Spawnpoint.
--All of this is in a LocalScript
local Player = game:GetService("Players").LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if Player:GetRankInGroup(*groupID*) >= 3 then -- Checks if the player has a certain rank in my group
Player.TeamColor = BrickColor.new("Lapis") -- Changes the Player team
Player.Character:FindFirstChild("Humanoid").Health = 0 -Reset the Character so you can spawn in the base
else script.Parent.Parent.ERRORE.Visible = true
wait(3)
script.Parent.Parent.ERRORE.Visible = false -- If you don't have this rank, makes visible for 3 seconds a Error message I made
end
end)
For the first method, this is what happens: (Video linked)
and also the Only-team tools and the radio system i used didn’t show with my system. It looks like the things linked to the team doesn’t work proprely. I am thinking is something about the LocalScript, i mean maybe since the script is only local it doesn’t communicate with the server so the server things won’t work
For the second method i made something similar: you have to get a rank in a group to make the button visible, else the button will remain invisible. I tried it too but didn’t work (maybe scripting issues).
Can somone please help me with this problem? I really need this system for my Roleplay Game. Thanks
Changing the player’s team on the client is what is causing the issue here. The Team property doesn’t replicate to the server if you do it this way. You could use a RemoteEvent for client-server communication:
-- SERVER SCRIPT
local TeamChange = game.ReplicatedStorage.TeamChange -- This is a RemoteEvent
TeamChange.OnServerEvent:Connect(function(Player)
-- We check the player's rank again on the server to verify that they are actually this rank
-- Exploiters can fire events as well, so it is good practice to verify everything on the server
if Player:GetRankInGroup(*groupID*) >= 3 then -- Checks if the player has a certain rank in my group
Player.TeamColor = BrickColor.new("Lapis") -- Changes the Player team
Player.Character:FindFirstChild("Humanoid").Health = 0 -Reset the Character so you can spawn in the base
end
end)
-- LOCAL SCRIPT
local TeamChange = game.ReplicatedStorage.TeamChange -- This is a RemoteEvent
local Player = game:GetService("Players").LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if Player:GetRankInGroup(*groupID*) >= 3 then -- Checks if the player has a certain rank in my spawn in the base
-- Fire event to server
TeamChange:FireServer()
else
script.Parent.Parent.ERRORE.Visible = true
wait(3)
script.Parent.Parent.ERRORE.Visible = false -- If you don't have this rank, makes visible for 3 seconds a Error message I made
end
end)
Uh sorry I have another question: if instead of only a rank i need more than one, for example, to change team many people with different ranks can do it, how i should write it? Is adding instead of the rank number the formula
if Player:GetRankInGroup(*groupID*) == {*rank*, *rank, *rank*} then
If they were on the same team, there are two ways you can go about it:
Case one: You can get the highest number rank and the lowest number rank and check if the player’s rank lies between that interval:
-- In this example, High Rank is 255, Middle Rank is 254, and Low Rank is 253:
local Rank = Player:GetRankInGroup(*groupID*)
if (Rank <= 255 and Rank >= 253) then
-- This player is either High Rank, Middle Rank, or Low Rank
end
Case two: Let’s say you didn’t want Middle Rank to be able to switch to this team. In that case, our previous example no longer works. Luckily, we can just create a table that consists of the ranks that have permission to switch to this team and check if the player’s rank is in said table.
local Ranks = {255, 253} -- High Rank, Low Rank
if table.find(Ranks, Player:GetRankInGroup(*groupID*)) then
-- This player is either High Rank or Low Rank
end