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

LocalPlayers a nil value?

So, recently I have migrated my testing Level System and Experience into the ROBLOX data save scripts, however I want to keep the level system scripts for the XP bar.

However when I do so, and edit the script it says LocalPlayers is a nil value when I'm using it in a variable.

Here is the script:

local player = game.Players.LocalPlayer
Level = game.Players.LocalPlayer.Data:WaitForChild("Level")
XP = game.Players.LocalPlayer.Data:WaitForChild("XP")
XP.Changed:connect(function() XPChange(player,XP,Level) end)

function XPChange(Player,XP,Level) ------ XPChanged function
	if XP.Value >= Level.Value*150  then ----- this function occours happens if the Level's Value is greater or equal to this 150 ([Note]: Change 150 to the max XP)
		XP.Value = 0 --- Resets the XP
		Level.Value = Level.Value+ 1
	end
end

Thanks for the help!

2 comments

0

It says the error if for line 3.

0

Firstly, are you using a local script? And also, if you just defined "game.Players.LocalPlayer" as "player", why did you repeat it again in Line 2 and 3??

1 answer

The only way to get that error is that you are not using a localscript!

1 comment

0

Put wait(.1) at the top of the script.

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