I’ve been trying for around an hour and havent found a way to do it
I have a keycard tool and I want it to change a specific text label to the team name of the player carrying it can anyone please help me with that?
2 Likes
Doesn’t this do the trick?
-- Local script
local tool = script.Parent
local player = game.Players.LocalPlayer
local team = player.Team
if team then
tool.Name = (team.Name.." keycard")
end
or
-- Normal script
local tool = script.Parent
local player = tool.Parent.Parent --tool.Parent is backpack
local team = player.Team
if team then
tool.Name = (team.Name.." keycard")
end
1 Like
Inside the keycard in a LocalScript do:
local player = game:GetService("Players").LocalPlayer
local teamNameLabel = -- Where your TextLabel is located
player:GetPropertyChangedSignal("Team"):Connect(function()
teamNameLabel.Text = player.Team and player.Team.Name or "Neutral"
end)
Edit: If you want to replicate it to other players it’s a bit more complicated, you’ll need to do this in a server script instead:
local players = game:GetService("Players")
local tool = -- The keycard tool
local teamNameLabel = -- Where your TextLabel is located
tool.Equipped:Once(function()
local player = players:GetPlayerFromCharacter(tool.Parent)
player:GetPropertyChangedSignal("Team"):Connect(function()
teamNameLabel.Text = player.Team and player.Team.Name or "Neutral"
end)
end)
1 Like
I tried that (The server script) but it doesnt work.
The text on the text label won’t change and I even tried it on a different empty place
Can I see the script, please? I need it to see where the TextLabel is located
local players = game:GetService("Players")
local tool = script.Parent -- The keycard tool
local teamNameLabel = script.Parent.Handle.SurfaceGui.Team -- Where your TextLabel is located
tool.Equipped:Once(function()
local player = players:GetPlayerFromCharacter(tool.Parent)
player:GetPropertyChangedSignal("Team"):Connect(function()
teamNameLabel.Text = player.Team and player.Team.Name or "Neutral"
end)
end)
Your problem is you arent using a local script. Server scripts cant tell when a tool is equipped
This should fix the problem:
local players = game:GetService("Players")
local tool = script.Parent -- The keycard tool
local teamNameLabel = script.Parent.Handle.SurfaceGui.Team -- Where your TextLabel is located
tool.Equipped:Once(function()
local player = players:GetPlayerFromCharacter(tool.Parent)
teamNameLabel.Text = player.Team and player.Team.Name or "Neutral"
player:GetPropertyChangedSignal("Team"):Connect(function()
teamNameLabel.Text = player.Team and player.Team.Name or "Neutral"
end)
end)
@FroDev1002 Yes they can, test it out and see for yourself
Ohh well never mind then. My bad
1 Like
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.