Attempt to compare number error

Hello, recently I’ve tried to make a script that makes it show a button once a player has a certain value.

Currently, I’m getting an error which says:

attempt to compare number <= Instance

Here’s the script:

local Player = game.Players.LocalPlayer
local leaderstats = Player.leaderstats
local PassLevel = leaderstats.PassLevel

if PassLevel >= 1 then 
	script.Parent.Visible = true
end

The thing that should happen is, when a player hits their Pass Level value to 1, it makes the button/ui visible. And, if it’s 2 or more, it will still show.

I’m not too sure how to fix this, any thing will help.

Thanks.

do

if PassLevel.Value >= 1 then 

should work. if you have any questions then feel free to ask

1 Like
local Part = script.Parent
local Player = game.Players.LocalPlayer
local leaderstats = Player.leaderstats
local PassLevel = leaderstats.PassLevel

if PassLevel.Value >= 1 then 
	Part.Visible = true
end
1 Like

I cannot believe how stupid I am, when I saw this I was so shocked that I forgot to add .Value, lol.

Thank you for the help.

1 Like

Seeing that I missed the .Value I felt so dumb, lol.

Thanks for the help!!

No problem, you probably want something like this instead.

local Part = script.Parent
local Player = game.Players.LocalPlayer
local leaderstats = Player.leaderstats
local PassLevel = leaderstats.PassLevel

PassLevel.Changed:Connect(function()
	if PassLevel.Value >= 1 then 
		Part.Visible = true
	end
end)

Because before the part will be only be visible if “PassLevel” starts at 1 (the conditional statement is only executed once). Whereas with the above whenever the value of “PassLevel” changes the conditional statement is checked.

1 Like