Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

2 comments

0

is bin in youre backpack then do p.Backpack.bin

0

bin isnt backpack bin is like leaderstats

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.