So for my obby checkpoints, I am using teams & spawns. I dont want to get messy with tons of stages, so I disabled the playerlist, and made a GUI with the following script to tell them what stage they are on.
It doesnt work. Why?
game.Players.PlayerAdded:Connect(function()
local team = game.Players.LocalPlayer.Team.Name
team = team:sub(6,team.length)
script.Parent.Text = "Stage: "..team
end)
game.Players.LocalPlayer.Team.Changed:Connect(function()
local team = game.Players.LocalPlayer.Team.Name
team = team:sub(6,team.length)
script.Parent.Text = "Stage: "..team
end)
I don’t really understand what you are trying to accomplish here but I think this may help out;
game.Players.LocalPlayer.Team.Changed:Connect(function()
local team = game.Players.LocalPlayer.Team.Name
local NumString = string.len(team)
team = tonumber(string.sub(team,NumString,NumString)) -- gets the 6th part of the name (im hoping the number) and changes it to a number
script.Parent.Text = "Stage: "..team
end)
EDIT: You actually dont need the “tonumber” part since it will return a string value and your turning it into a name.
local Players = game:GetService("Players")
local User = Players.LocalPlayer
local currentteam = nil
Players.PlayerAdded:Connect(function(plr)
plr:WaitForChild("Teams")
local team = plr.Team
script.Parent.Text = team
currentteam = team
end)
Players.LocalPlayer.Team.Changed:Connect(function()
if User.Team ~= currentteam then
script.Parent.Text = User.team
currentteam = User.team
end
end)
I feel like this is all you need, although I hardly ever use the “Changed” event when I code so I’m not to used to what it does / effects.
Yeah its still at 0. I did some testing and the Changed event isn’t being fired. Do you have any idea, of a different way to auto-detect and change it?
local Players = game:GetService("Players")
local User = Players.LocalPlayer
local currentteam = nil
Players.PlayerAdded:Connect(function(plr)
plr:WaitForChild("Teams")
local team = plr.Team
script.Parent.Text = team
currentteam = team
end)
Players.LocalPlayer:GetPropertyChangedSignal("Team"):Connect(function()
if User.Team ~= currentteam then
script.Parent.Text = User.team
currentteam = User.team
end
end)
If you’re making a GUI that displays the score of your own player, you shouldn’t add the PlayerAdded event, this would be used if you were recording the scores of every player who joined apart from yourself, instead you should do something along these lines:
local plr = game.Players.LocalPlayer
local playerStage = plr.Stage -- Change this to the value that stores your stage
local textDisplay = script.Parent.TextLabel -- Change this to the textLabel that is displaying your stage
textDisplay.Text = playerStage.Value
playerStage.Changed:Connect(function(newValue)
textDisplay.Text = playerStage.Value
end)