Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't my textLabel go invisible if stat is below 1?

Asked by 9 years ago

Im trying to make my textlabel become invisible if Stat > 1. Here is the code.

p = game.Players.LocalPlayer

while true do
    wait()
    if p.bin.StatPoints.Value >= 1 then
        script.Parent.Visible = nil
    elseif
        p.bin.StatPoints.Value <= 1 then
        script.Parent.Visible = true
    end
end
0
is bin in youre backpack then do p.Backpack.bin Kryddan 261 — 9y
0
bin isnt backpack bin is like leaderstats attackonkyojin 135 — 9y

1 answer

Log in to vote
0
Answered by
ImageLabel 1541 Moderation Voter
9 years ago

You might want to considering limiting your use to infinite loops whenever possible. You could track changes to properties of an object use the Changed event, which is a lot more efficient.

You also made a little error in checking the value of StatPoints on line 5 ( >1=)

Finally if on one line you are checking for (greater than or equal to) and on the other you are checking (less than or equal to), both statements would be true, therefore both different codes would run


player = game.Players.LocalPlayer
statsBin = player:WaitForChild('bin')
statPoints = statsBin:WaitForChild('StatPoints')

statPoints.Changed:connect(function (property)
    -- wait for change in object `statPoints`
    if tostring(property) == 'Value' then
        -- if change is its Value property
        if statPoints[property] > 1 then
            --if value is over one do
            script.Parent.Visible = false
        elseif statPoints[property] < 1 then
            --if value is less than 1 do
            scrippt.Parent.Visible = true
        end
    end
end)
Ad

Answer this question