Text Not Updating

Really unsure as to why my text is not updating within this script, if the boost value is 5, the text should say 10X GEMS, however, instead it prints out Unexpected Value: 5. Not sure why this doesn’t work as if the value is 5 the text should update, so the condition should have been accepted. Any help would be appreciated.

local player = game.Players.LocalPlayer
local boosts = player:WaitForChild("Multipliers"):WaitForChild("Boosts")

local function updateText()
	print("Boosts value:", boosts.Value)
	if boosts.Value == 0 then
		script.Parent.Text = "2X GEMS!"
	elseif boosts.Value == 2 then
		script.Parent.Text = "5X GEMS!"
	elseif boosts.Value == 5 then
		script.Parent.Text = "10X GEMS!"
	else
		print("Unexpected value:", boosts.Value)
	end
end

updateText()

boosts:GetPropertyChangedSignal("Value"):Connect(updateText)

Is the value of boosts a string? That would explain why 5 ~= “5”

If that is the case you can add tonumber(boosts.Value) or change the boosts instance to a NumberValue

(side note, you can use boosts.Changed:Connect(updateText) since the changed event for a value fires only when the Value is changed)

1 Like

:man_facepalming: - forgot to use an IntValue instead of a string, my bad thanks

1 Like

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