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

How would I start a script to convert a Value to another Value?

{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!

1 comment

0

Im not good at this stuff, so im going to offer this thing instead! https://devforum.roblox.com/t/level-systems-part-1/296963

2 answers

✓ Accepted answer

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)

6 comments

0

I just saw your scripts you made. Just change the paths around and connect the values to your datastore and you should be set.

0

Also, put them all in one script.

0

This is a neat solution!

0

I'll test!

0

Hmm it seems not to be working for me possibly the way I put it in

0

@vinvincentthecat1 Add me on Discord I'll give extra support there. xWhiteHat#4788

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...

3 comments

0

That is the same thing that he used?

0

It is the same he just got rid of the Local EXP.

0

Does that help?

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