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

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

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

2 comments

0

Whats that first line?

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?

1 answer

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.

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