When I check the error it says ServerScriptService.LevelUp:2: attempt to index nil with 'FindFirstChild' If anyone can help me I would be gratefull here's the script
local plr = game.Players.LocalPlayer local Stats = game.Players.LocalPlayer:FindFirstChild("Stats") --This is finds the Stats local XP = Stats:FindFirstChild("XP") -- This should find XP if XP.Value > 70 *plr.leaderstats.Level.Value then -- I wanted to do if the XP is higher then 70 times level so what I went times by level is when you get lvl 2 it times it to 140 plr.leaderstats.Level.Value = plr.leaderstats.Level.Value +1 -- this gives it end
Hope I explained it right to you guys Anyone can help thanks again
local players = game:GetService("Players") local function onplayeradded (player) local leaderstats = Instance.new("Folder") local stats = Instance.new("Folder") local level = Instance.new("IntValue") local maxxp = Instance.new("IntValue") local xp = Instance.new("IntValue") leaderstats.Name = "leaderstats" stats.Name = "stats" level.Name = "Level" maxxp.Name = "maxxp" xp.Name = "xp" leaderstats.Parent = player stats.Parent = player level.Parent = leaderstats maxxp.Parent = stats xp.Parent = stats level.Value = 1 maxxp.Value = 70 xp.Value = 0 while true do wait(0.1) --You can change this however you want. if xp.Value >= maxxp.Value then maxxp.Value = maxxp.Value * 2 xp.Value = 0 level.Value = level.Value + 1 end end end players.PlayerAdded:Connect(onplayeradded)
I think your problem is with line 3 it's trying to find the child "XP" when it does not exist as you did not create it with Instance and same for the stats
I would remove the stats stuff you made manually and create it with Instance by checking when a player joins the game with a server script in ServerScriptService
Example:
game.Players.PlayerAdded:Connect(function(plr) -- You can change plr to anything as its just a local value local stats = Instance.new("Folder") -- The object you make with instance can be changed stats.Name = "leaderstats" -- If the name is not leaderstats it will not show on the leaderboard but thats your choice stats.Parent = plr local lv = Instance.new("IntValue") lv.Name = "Level" -- Name string can be change lv.Parent = stats local maxxp = Instance.new("IntValue") maxxp.Name = "Max XP" -- Name string can be change maxxp.Parent = plr local xp = Instance.new("IntValue") xp.Name = "XP" -- Name string can be change xp.Parent = stats while wait() do -- Same thing as while true do but It won't crash your game if xp.Value >= maxxp.Value then xp.Value = xp.Value - maxxp.Value -- I fixed up your exp decrease script for ya so it does not default it to 0 instead it removes as much xp is needed to level up! maxxp.Value = maxxp.Value * 2 lv.Value = lv.Value + 1 end end end)
If you want this stuff to be saved I would look at datastore tutorials they are complicated for beginners but still is needed for a rpg game!