This may help, but it can also help in debugging. If warn() doesn’t show in the console, just print().
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
-- Ensure the player and team properties are valid
if Player and Player.Team then
-- Set the text to the player's team name if it exists
if Player.Team.Name then
script.Parent.Text = Player.Team.Name
else
warn("Player's team does not have a name")
end
-- Set the text color to the team's color if it exists
if Player.Team.TeamColor then
script.Parent.TextColor3 = Player.Team.TeamColor.Color
else
warn("Player's team does not have a TeamColor property")
end
else
warn("Player or Player.Team is nil")
end
-- Destroy the script after execution to clean up
script:Destroy()
local Tool = script.Parent
local Players = game:GetService("Players")
local Player,Team = nil,nil
Tool.Equipped:Connect(function()
Player = Players.LocalPlayer
Team = Player.Team.Name
end)
So I did try that, had to fix the script.parent. Otherwise, it still didn’t work. Came back with an error.
Players.Bjorn_Kronos.Backpack.Level-1.Handle.SurfaceGui.Frame.Team.TeamSet:7: attempt to index nil with ‘Team’ - Server - TeamSet:7
00:17:38.847 Script ‘Players.Bjorn_Kronos.Backpack.Level-1.Handle.SurfaceGui.Frame.Team.TeamSet’, Line 7 - Studio - TeamSet:7
This is the screenshot of the tool to see if that would help out.
Just checked the image, your script Isn’t a LocalScript… and Player.LocalPlayer only works with LocalScripts
Use this instead
local Tool = script.Parent
local Players = game:GetService("Players")
local Player,Team = nil,nil
Tool.Equipped:Connect(function()
if Players:GetPlayerFromCharacter(Tool.Parent) == nil then return end
Player = Players:GetPlayerFromCharacter(Tool.Parent)
Team = Player.Team.Name
end)