Obby stage text

I have a difficulty chart game, i wanted a script that changes the text on a textlabel depending on what stage your own, so like theres a grey stage, a green stage, an orange stage, and a red one. how could i make this work?, i tried a script, but it didnt seem to work. Heres the code:

local stage1 = game.Workspace.Stage1
local stage2 = game.Workspace.Stage2
local stage3 = game.Workspace.Stage3
local stage4 = game.Workspace.Stage4



local stageText = game.StarterGui.StageLabel.TextLabel

stage1.touched:Connect(function(changetext)
	local humanoid = changetext.Parent:FindFirstChild("Humanoid")
	if humanoid then
		stageText.Text = "Stage 1, beginner."
	end
end)

stage2.touched:Connect(function(changetext)
	local humanoid = changetext.Parent:FindFirstChild("Humanoid")
	if humanoid then
		stageText.Text = "Stage 2, Intermediate."
	end
end)

local stageText = game.StarterGui.StageLabel.TextLabel

stage3.touched:Connect(function(changetext)
	local humanoid = changetext.Parent:FindFirstChild("Humanoid")
	if humanoid then
		stageText.Text = "Stage 3, Hard."
	end
end)

stage4.touched:Connect(function(changetext)
	local humanoid = changetext.Parent:FindFirstChild("Humanoid")
	if humanoid then
		stageText.Text = "Stage 4, Insane."
	end
end)


Also, this is a local script inside of starter player scripts.

2 Likes

The reason your code doesn’t work is because you are accessing the gui inside of game.StarterGui, which is not the same as the gui that your character is currently seeing.

Gui that your character is currently seeing is accessible via game.Players.LocalPlayer.PlayerGui.

However an even better fix than changing the above is to put the LocalScript inside of the Gui itself, that way you can simply do local stageText = script.Parent.TextLabel for example

2 Likes

Thanks, also another problem was i forgot to anchor the stage parts, they were falling off the map!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.