Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Script by xmaanzach
- local DataStore = game:GetService("DataStoreService")
- local Nivel = 1
- local Experiencia = 0
- local XP_Necesaria = 20
- Nivel = DataStore:GetDataStore("Niveles")
- Experiencia = DataStore:GetDataStore("Experiencia")
- XP_Necesaria = DataStore:GetDataStore("XPN")
- --// Creando el leaderstats //--
- game.Players.PlayerAdded:Connect(function(Player)
- local PlayerId = tostring(Player.UserId)
- local leaderstats = Player:FindFirstChild("leaderstats")
- if leaderstats == nil then
- leaderstats = Instance.new("Folder")
- leaderstats.Name = "leaderstats"
- leaderstats.Parent = Player
- end
- local Level = leaderstats:FindFirstChild("Nivel")
- if Level == nil then
- Level = Instance.new("IntValue")
- Level.Name = "Nivel"
- end
- local Exp = leaderstats:FindFirstChild("Experiencia")
- if Exp == nil then
- Exp = Instance.new("IntValue")
- Exp.Name = "Experiencia"
- end
- local Xpn = leaderstats:FindFirstChild("ExpNeeded")
- if Xpn == nil then
- Xpn = Instance.new("IntValue")
- Xpn.Name = "ExpNeeded"
- end
- Level.Value = Nivel:GetAsync(PlayerId) or 1
- Exp.Value = Experiencia:GetAsync(PlayerId) or 0
- Xpn.Value = XP_Necesaria:GetAsync(PlayerId) or 20
- Level.Parent = leaderstats
- Exp.Parent = leaderstats
- Xpn.Parent = leaderstats
- Exp.Changed:Connect(function()
- if Player.leaderstats.Experiencia.Value >= Player.leaderstats.ExpNeeded.Value then
- Level.Value = Level.Value + 1
- Xpn.Value = math.floor(Xpn.Value * 2)
- Exp.Value = 0
- Nivel:SetAsync(PlayerId, Level.Value)
- Experiencia:SetAsync(PlayerId, Exp.Value)
- XP_Necesaria:SetAsync(PlayerId, Xpn.Value)
- end
- end)
- end)
- --// Guardando los Datos cuando el jugador abandona el juego //--
- game.Players.PlayerRemoving:Connect(function(Player)
- local PlayerId = tostring(Player.UserId)
- Nivel:SetAsync(PlayerId, Player.leaderstats.Nivel.Value)
- Experiencia:SetAsync(PlayerId, Player.leaderstats.Experiencia.Value)
- XP_Necesaria:SetAsync(PlayerId, Player.leaderstats.ExpNeeded.Value)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement