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.
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
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.