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
It says the error if for line 3.
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??