Closed closed closed closed closed closed closed

closed closed closed closed closed closed closed

The code above will only run once and never again. If you want it to keep checking if the player has enough orbs, you’ll need to connect it to either a loop or an event. Since you’re working with values, .Changed should do the trick.

local player = game.Players.LocalPlayer

player.leaderstats.Orbs.Changed:Connect(function()
    if player.leaderstats.Orbs.Value >= 1200 then
        script.Parent.Text = “TEST”
        script.Parent.TextColor3 = Color3.new(0, 0.666667, 0)
    end
end)
2 Likes

closed closed closed closed closed closed closed closed

2 Likes

Welcome to the world of scripting my good friend! :slightly_smiling_face:

It seems like your issue is something simple, sometimes the leaderstats Instance may not entirely load in time in relation with the LocalScript, which is why we use a nifty function called WaitForChild() :wink: (This is to make sure that there truly is an Object that’s named leaderstats and Orbs)

You can also detect whenever your Orbs Value gets changed via using a Changed event, this is handy especially for checking new values that get updated! (Already been noted)

local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local Orbs = leaderstats:WaitForChild("Orbs")

local function CheckNewValue(NewValue) --This is actually the new value that's called a parameter!
    if NewValue >= 1200 then
        script.Parent.Text = "TEST"
        script.Parent.TextColor3 = Color3.new(0, 0.666667, 0)
    end
end

Orbs.Changed:Connect(CheckNewValue)

(I am aware that this has been fixed, but this script is to prepare for any unusual occurrences happening)

1 Like