Hello devform,
Recently I’ve been making nametags for my game, and I need help making the nametags change-able from the player’s GUI.
The teams are stored in a modulescript, here’s the structure for it:
local teams = {}
teams.Something = {
Name = "Something",
Color = Color3.fromHex("HexCodeHere"),
Subroles = {
["SubRole1"] = {
Name = "HelloWorld",
Color = Color3.fromHex("HexCodeHere"),
Staff = false,
Pass = 0
},
}
return teams
This is relatively simple, for each one, Pass is the gamepass that the user will be prompted to buy if they do not have it already to access the team
Staff is if it is restricted to users who are marked as staff, and will only be accessible to them.
This module is designed for multiple teams and all of their subroles.
From an eartlier post, I have figured out how to install nametags, that is not the problem.
The current issue is trying to figure out how to apply changes to the nametags.
I’ve tried this through multiple different ways, which have either been complicated or confuse me too much to figure out.
Here is the localscript that sends the information of the changes:
-- Services
local RepStore = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local plr = Players.LocalPlayer
-- RemoteEvent reference (Optional for validation purposes)
local ClickEvent = RepStore.Nametags:WaitForChild("TagInfo")
-- Function to handle button clicks and switch teams
local function onButtonClicked(role, subrole)
-- Optionally use RemoteEvent for validation
ClickEvent:FireServer(role, subrole)
end
-- Function to setup button connections
local function setupButtons(parentFrame, role)
for _, button in ipairs(parentFrame:GetChildren()) do
if button:IsA("TextButton") then
local subrole = button.Name
button.MouseButton1Click:Connect(function()
onButtonClicked(role, subrole)
end)
end
end
end
-- Setting up buttons for different roles
local Subroles = script.Parent.Subroles
setupButtons(Subroles.Staff.Name, "Staff")
Here’s the regular script that receives the changes:
local RepStore = game:GetService("ReplicatedStorage")
local Teams = game:GetService("Teams")
-- Function to handle team switching
local function switchTeam(player, role, subrole)
if role == "Staff" then
if subrole == "Creator" then
player.Team = Teams.Creator
elseif subrole == "Contributor" then
player.Team = Teams.Contributor
end
end
end
-- RemoteEvent to handle team switching (Optional for validation purposes)
local buttonClickedEvent = RepStore.Nametags:WaitForChild("TagInfo")
buttonClickedEvent.OnServerEvent:Connect(function(player, role, subrole)
switchTeam(player, role, subrole)
end)
Yes I have tried chatgpt, and I ask you to ignore the parts where it establishes the Teams service.
Any help is appreciated.