{Information}
So I want to know how to start a script to convert Value1 to another named Value2 when Value1 has a value of 50 then it will automatically convert it to a value of 2 for Value2, Basically the Values are the String Values in the leaderstats folder. For example, Value1 will be called EXP or XP and Value2 will be called Levels/Ranks. So how would I automatically convert 50 EXP/XP to 1 Level/Rank? Basically a level-up system, and how would I make the EXP/XP needed to Level/Rank up multiply by 2?
{Scripts}
LeaderStats(Works(Script)
local DataStoreService = game:GetService("DataStoreService") local myDataStore = DataStoreService:GetDataStore("myDataStore") game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local Levels = Instance.new("IntValue") Levels.Name = "Levels" Levels.Parent = leaderstats Levels.Value = 1 local Kills = Instance.new("IntValue") Kills.Name = "Kills" Kills.Parent = leaderstats Kills.Value = 0 local Gems = Instance.new("IntValue") Gems.Name = "Gems" Gems.Parent = leaderstats Gems.Value = 50 local EXP = Instance.new("IntValue") EXP.Name = "EXP" EXP.Parent = leaderstats EXP.Value = 0 local data local success, errormessage = pcall(function() data = myDataStore:GetAsync(player.UserId.."-Levels") data = myDataStore:GetAsync(player.UserId.."-Kills") data = myDataStore:GetAsync(player.UserId.."-Gems") data = myDataStore:GetAsync(player.UserId.."-EXP") end) if success then Levels.Value = data Kills.Value = data Gems.Value = data EXP.Value = data else print("There was a error whilst getting your data") warn(errormessage) end end) game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall(function() myDataStore:SetAsync(player.UserId.."-Levels",player.leaderstats.Levels.Value) myDataStore:SetAsync(player.UserId.."-Kills",player.leaderstats.Kills.Value) myDataStore:SetAsync(player.UserId.."-Gems",player.leaderstats.Gems.Value) myDataStore:SetAsync(player.UserId.."-EXP",player.leaderstats.EXP.Value) end) if success then print("Player Data successfully saved!") else print("There was a error when saving data") warn(errormessage) end end)
Converter(Does not work(Script)
local Level = game.Players.LocalPlayer.leaderstats.Levels.Value local EXP = game.Players.LocalPlayer.leaderstats.EXP.Value if game.Players.LocalPlayer.leaderstats.EXP == "50" then game.Players.LocalPlayer.leaderstats.EXP -50 game.Players.LocalPlayer.leaderstats.Level +1 end
If anybody could help me start off my script I would really appreciate it!
Hello, vincentthecat1!
You could use the Changed event to see if the player's EXP is greater than or equal to the expneeded, if it is then it gives them 1 level Below is a script I made to hopefully fit what you asked for.
Find any errors? Feel free to reply to this and let me know!
game.Players.PlayerAdded:Connect(function(player) local ExpPath = player:WaitForChild("leaderstats").EXP local ExpNeededPath = player:WaitForChild("leaderstats").ExpNeeded local LevelPath = player:WaitForChild("leaderstats").Level ExpPath.Changed:Connect(function(new) if new >= ExpNeededPath.Value then LevelPath.Value = LevelPath.Value + 1 -- Adds the level if EXP is greater than or equal to ExpNeeded ExpNeededPath.Value = ExpNeededPath.Value * 2 -- Multiplys value by 2 end end) end)
local Level = game.Players.LocalPlayer.leaderstats.Levels.Value if game.Players.LocalPlayer.leaderstats.EXP.Value == "50" then game.Players.LocalPlayer.leaderstats.EXP.Value -50 game.Players.LocalPlayer.leaderstats.Levels.Value +1 --.Value end
Try this...