[ .. closed .. ]

[ … CLOSED … ]i found other solution

How much of programming do you know? What do you expect this to do?

i know a little of each
therefore, this is a leaderstat with data storage and "level up"el up’’

i have added some variables bcause theres no much to change.

i changed all WaitForChild for FindFirstChild bcause it cant find a thing before checking if it exists, i think it work like this

here goes the modifies

> local level = 1
> local exp = 0
> local axp = 20
> local fc = 100
> local Rank = "Genin"
> 
> local InStudio = game:GetService("RunService"):IsStudio()
> 
> if not InStudio then
> 	level = game:GetService("DataStoreService"):GetDataStore("Levels")
> 	exp = game:GetService("DataStoreService"):GetDataStore("EXP")
> 	axp = game:GetService("DataStoreService"):GetDataStore("AXP") -- Amount of exp needed to level up.
> 	fc = game:GetService("DataStoreService"):GetDataStore("FC")
> 	Rank = game:GetService("DataStoreService"):GetDataStore("Rank")
> end
> 
> function savedata(dataname, playerid, value)
> 	if InStudio then return end
> 	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.Name = "Level"
> 	
> 	local xpz = Instance.new("NumberValue")
> 	xpz.Name = "Exp"
> 	
> 	local xpn = Instance.new("IntValue")
> 	xpn.Name = "ExpNeeded"
> 	
> 	local fcz = Instance.new("IntValue")
> 	fcz.Name = "FC"
> 	
> 	local rnk = Instance.new("StringValue")
> 	rnk.Name = "Rank"
> 	
> 	if not InStudio then
> 		xpn.Value = axp:GetAsync(tostring(player.userId)) or 20
> 		xpz.Value = exp:GetAsync(tostring(player.userId)) or 0
> 		levelz.Value = level:GetAsync(tostring(player.userId)) or 1
> 		fc.Value = level:GetAsync(tostring(player.userId)) or 100
> 		rnk.Value = level:GetAsync(tostring(player.userId)) or "Genin"
> 	else
> 		xpn.Value = axp
> 		xpz.Value = exp
> 		levelz.Value = level
> 		fcz.Value = fc
> 		rnk.Value = Rank
> 	end
> 	
> 	levelz.Parent = leader
> 	xpz.Parent = leader
> 	xpn.Parent = leader
> 	fcz.Parent = leader
> 	rnk.Value = leader
> 	
> 	xpz.Changed:connect(function()
> 		if player.leaderstats:FindFirstChild("Exp").Value >= player.leaderstats:FindFirstChild("ExpNeeded").Value then
> 			levelz.Value = levelz.Value + 1
> 			fcz.Value = fcz.Value + 100
> 			
> 		--[[Here's a cool formula you can try out for higher exp
> 			n = level
> 			a = exp required to level up
> 			
> 			a = ((n(n+1)/2)*100
> 		]]
> 			
> 			xpn.Value = xpz *2
> 			xpz.Value = 0	
> 			
> 			savedata(level, player.userId, levelz.Value)
> 			savedata(exp, player.userId, xpz.Value)
> 			savedata(axp, player.userId, xpn.Value)
> 			savedata(fc, player.userId, fcz.Value)
> 			savedata(Rank, player.userId, rnk.Value)
> 		else
> 			savedata(level, player.userId, levelz.Value)
> 			savedata(exp, player.userId, xpz.Value)
> 			savedata(axp, player.userId, xpn.Value)
> 			savedata(fc, player.userId, fcz.Value)
> 			savedata(Rank, player.userId, rnk.Value)
> 		end
> 		savedata(level, player.userId, levelz.Value)
> 		savedata(exp, player.userId, xpz.Value)
> 		savedata(axp, player.userId, xpn.Value)
> 		savedata(fc, player.userId, fcz.Value)
> 		savedata(Rank, player.userId, rnk.Value)
> 	end)
> end)
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> game.Players.PlayerRemoving:connect(function(player)
> 	savedata(level, player.userId, player.leaderstats.Level.Value)
> 	savedata(exp, player.userId, player.leaderstats.Exp.Value)
> 	savedata(axp, player.userId, player.leaderstats.ExpNeeded.Value)
>     savedata(fc, player.userId, player.leaderstats.FC.Value)
>  	savedata(Rank, player.userId, player.leaderstats.Rank.Value)
>    
> end)