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

why doesnt this XP script work, it doesnt work it doesnt show a leader boeard with XP and Level?!

local level = game:GetService("DataStoreService"):GetDataStore("Levels") local xp = game:GetService("DataStoreService"):GetDataStore("XP") local axp = game:GetService("DataStoreService"):GetDataStore("AXP") -- stands for amount xp needed to level up.

function savedata(dataname, playerid, value) game:GetService("DataStoreService"):GetGlobalDataStore(dataname):SetAsync(playerid, value)

end

game.Players.PlayerAdded:connect(function(player) local leader = Instance.new("Folder") leader.Name = "LeaderStats" leader.Parent = player local levelz = Instance.new("IntValue") levelz.Value = level:GetAsync(tostring(player.userid)) or 1 levelz.Name = "Level" levelz.Parent = player:WaitForChild("Leaderstats") local xpz = Instance.new("NumberValue") xpz.Value = xp:GetAsync(tostring(player.userid)) xpz.Name = "XP" xpz.Parent = player local xpn = Instance.new("IntValue") xpn.Value = axp:GetAsync(tostring(player.userid)) or 700 xpn.Parent = player

xpz.Changed:coonect(function()
	if player:WaitForChild("XP").Value >= player:WaitForChild("XpNeeded").Value then
		levelz.Value = levelz.Value+1
		xpn.Value = xpn.Value+700
		savedata("Levels",player.userid,levelz.Value)
		savedata("XP",player.userid,xpz.Value)
		savedata("AXP",player.userid,xpn.Value)
	else
		savedata("Levels",player.userid,levelz.Value)
		savedata("XP",player.userid,xpz.Value)
		savedata("AXP",player.userid,xpn.Value)
	end 
	savedata("Levels",player.userid,levelz.Value)
    savedata("XP",player.userid,xpz.Value)
    savedata("AXP",player.userid,xpn.Value)
end)

end) game.Players.PlayerRemoving:connect(function(player) savedata("Levels",player.userid,player.leaderstats.Level.Value) savedata("XP",player.userid,player.XP.Value) savedata("AXP",player.userid,player.XpNeeded.Value) end)

2 answers

Try This!

local xp = Instance.new("IntValue") 
xp.Name = "XP" 
xp.Value= 0 

local level = Instance.new("IntValue") 
level.Name = "Level" 
level.Value = 1 

local c = Instance.new("IntValue") 
c.Name = "Gold" 
c.Value = 0 

Makes you have Level 1, Gold 0 and Xp 0 


function onXPChanged(player, XP, level) 
if Xp.Value>=level.Value * 10 then 
Xp.Value = Xp.value - level.Value * 10 
level.Value = level.Value + 1 
end 
end

2 comments

0

where should i paste this??? will the rank save , and thank you :)))

0

you need to make a separate system for the save

Is doesn't work because you wrote player.userId with a lowercase i. Try to rewrite it with a capital.

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