Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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

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 firestarroblox123 440 — 4y

2 answers

Log in to vote
3
Answered by
NotedAPI 810 Moderation Voter
4 years ago

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)
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. NotedAPI 810 — 4y
0
Also, put them all in one script. NotedAPI 810 — 4y
0
This is a neat solution! firestarroblox123 440 — 4y
0
I'll test! vincentthecat1 199 — 4y
View all comments (2 more)
0
Hmm it seems not to be working for me possibly the way I put it in vincentthecat1 199 — 4y
0
@vinvincentthecat1 Add me on Discord I'll give extra support there. xWhiteHat#4788 NotedAPI 810 — 4y
Ad
Log in to vote
0
Answered by
gloveshun 119
4 years ago
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...

0
That is the same thing that he used? firestarroblox123 440 — 4y
0
It is the same he just got rid of the Local EXP. vincentthecat1 199 — 4y
0
Does that help? firestarroblox123 440 — 4y

Answer this question