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

What did I do wrong with leaderstats, how do I fix it?

Asked by 7 years ago
Edited 7 years ago

I'm working on a game. What did I do wrong with the leaderstats?

Players.Player1.PlayerGui.Menu1.MainMenu:115: attempt to compare number with userdata
local dagcount = 0
local function daggerclicked()
    if player.leaderstats2.Level >= 5 then
    dagcount = dagcount + 1
    if dagcount == 1 then
    dagger.Text = "Dagger: Owned"
    elseif dagcount == 2 then
        dagger.Text = "Dagger: Equipped"
    dagcount = 0
            end
    end
    end
0
Whats that first line? SimpleFlame 255 — 7y
0
I am very confused by the script here. I'm going to guess "leaderstats2" was a typo on line 4, and was supposed to be leaderstats? SkeletalReality 590 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

You have if player.leaderstats2.Level >= 5 then and I presume that this is line 115 in your original script. If that's correct, then the error is occurring because "Level" is an IntValue, and when lua sees "IntValue >= 5" it doesn't know what to do. You need to index it with .Value first, like so:

if player.leaderstats2.Level.Value >= 5 then

In the future, you should specify which line in the script you provided is the same as line 115 in your original script. I also recommend looking up how to indent properly.

Ad

Answer this question