Text isn't updating

Hello!

I am working on a battle-pass like system, and it all works except from this one thing, the text won’t update when the player leaves and rejoins.

For example, each reward is automatically claimable, so the player doesn’t need to claim the reward through a button - it’s how the entire system functions.

Now, there’s text in each reward frame which says “LOCKED” be default, and the script below changes it to say “CLAIMED” once the reward is claimed and unlocked. But, when the player leaves and rejoins, the text says locked instead of claimed.

Here’s the script:

local player = game.Players.LocalPlayer

local levelStats = player:WaitForChild("LevelStats")
local level = levelStats:WaitForChild("Level")
local xp = levelStats:WaitForChild("XP")

local levelClaimFolder = player:WaitForChild("LevelClaimFolder")
local levelClaim = levelClaimFolder:WaitForChild("LevelClaim")
local levelClaimEvent = game.ReplicatedStorage.RemoteEvents.ClaimEvents.LevelClaim

local claimCoinsEvent = game.ReplicatedStorage.RemoteEvents.ClaimEvents.ClaimCoins
local coins = player:WaitForChild("leaderstats"):WaitForChild("Coins")

local function update()
	if levelClaim.Value == 1 then
		claimCoinsEvent:FireServer()
		script.Parent.Text.Text = "CLAIMED"
		script.Parent.Text.TextColor3 = Color3.fromRGB(0, 255, 0)
		levelClaimEvent:FireServer()
	else
		coins.Value = coins.Value
		levelClaim.Value = levelClaim.Value
		script.Parent.Text.Text = "LOCKED"
		script.Parent.Text.TextColor3 = Color3.fromRGB(255, 0, 0)
	end
end

local function update2()
	if levelClaim.Value >= 1 then
		script.Parent.Text.Text = "CLAIMED"
		script.Parent.Text.TextColor3 = Color3.fromRGB(0, 255, 0)
	else
		script.Parent.Text.Text = "LOCKED"
		script.Parent.Text.TextColor3 = Color3.fromRGB(255, 0, 0)
	end
end

game.Players.PlayerAdded:Connect(function()
	update()
	update2()
end)

levelClaim.Changed:Connect(function()
	update()
	update2()
end)

Feel free to ask questions! Thanks!

This only runs when another player joins.

Move those functions outside that function and it should work.

Code:

local player = game.Players.LocalPlayer

local levelStats = player:WaitForChild("LevelStats")
local level = levelStats:WaitForChild("Level")
local xp = levelStats:WaitForChild("XP")

local levelClaimFolder = player:WaitForChild("LevelClaimFolder")
local levelClaim = levelClaimFolder:WaitForChild("LevelClaim")
local levelClaimEvent = game.ReplicatedStorage.RemoteEvents.ClaimEvents.LevelClaim

local claimCoinsEvent = game.ReplicatedStorage.RemoteEvents.ClaimEvents.ClaimCoins
local coins = player:WaitForChild("leaderstats"):WaitForChild("Coins")

local function update()
	if levelClaim.Value == 1 then
		claimCoinsEvent:FireServer()
		script.Parent.Text.Text = "CLAIMED"
		script.Parent.Text.TextColor3 = Color3.fromRGB(0, 255, 0)
		levelClaimEvent:FireServer()
	else
		coins.Value = coins.Value
		levelClaim.Value = levelClaim.Value
		script.Parent.Text.Text = "LOCKED"
		script.Parent.Text.TextColor3 = Color3.fromRGB(255, 0, 0)
	end
end

local function update2()
	if levelClaim.Value >= 1 then
		script.Parent.Text.Text = "CLAIMED"
		script.Parent.Text.TextColor3 = Color3.fromRGB(0, 255, 0)
	else
		script.Parent.Text.Text = "LOCKED"
		script.Parent.Text.TextColor3 = Color3.fromRGB(255, 0, 0)
	end
end

levelClaim.Changed:Connect(function()
	update()
	update2()
end)

update()
update2()
1 Like

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