Obby Stage GUI Help

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)

Extra Info:

Team names go like
Stage1
Stage2
etc.

1 Like

Is that all of your code? If you’re making a playerlist, you ought to clone a frame for each player and display their team on that, correct?

1 Like

No, its not a playerlist. Its just that players info.

1 Like

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.

2 Likes

Doesnt do anything. Says Stage: 0

1 Like

Can you please take a picture of where this “Teams” object is, and a picture of the properties you are trying to change?

Teams:
image

Property:

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.

Try this out though

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?

I did research and I believe this would work. Instance | Documentation - Roblox Creator Hub

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)

Ill try tomorrow morning (EST)

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)