So im pretty much a beginner at scripting and i need help with a button that lets you switch teams based on your rank in the group. Here is what i have so far but it doesnt work
local plyrservice = game:GetService("Players")
local player = plyrservice.LocalPlayer
script.Parent.MouseButton1Down:Connect(function()
if player:GetRankInGroup(6003664) == 249 then
player.TeamColor = BrickColor.new("Teal")
end
end)
The error i get is Players.Maxuter.PlayerGui.Team Select.Main.TeamSwitch.Script:6: attempt to index nil with 'GetRankInGroup'
You can’t change a player’s team from the client. In order to change the player’s team you will need to fire a RemoteEvent with the LocalScript then change the player’s team in the new script. As for the error on line 6 I think you should try running it on the server.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("Team Change")
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if player:GetRankInGroup(6003664) == 249 then
Event:FireServer(BrickColor.new("Teal"))
end
end)
Something with GetRankInGroup() is making a nil value it looks like. tbh I am not quite sure on this one. I never like using that anyway, I would use GetRoleInGroup() and find the role they have (name ex: Fan, Chef, Owner, etc.)
local plyr = game:GetService("Players").LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if plyr:GetRankInGroup(6003664) == 249 then --Change this (GROUPID) == (RANKID)
plyr.TeamColor = BrickColor.new("Teal") --Change color to the color of the team
plyr:LoadCharacter()
end
end)