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

How would i go about changing part of my code to save missing score?

Asked by 5 years ago

Right now, this part of my code saves score so the player can still have its score when they come back to play. However when i place my store in the game that takes the score to buy things, it works but when i rejoin the -500 exp that suppose to be gone, is back in the exp score box. Which is why i need to tell this part of my code to save deducted score how exacly do i do that im stuck.

This is part of it

function playerEntered(player)
    local killer = Instance.new("ObjectValue", player)
    killer.Name = "Killer"
    local killed = Instance.new("StringValue", player)
    killed.Name = "Killed"
    local kills = Instance.new("NumberValue", player)
    kills.Name = "Kills"
    local class = Instance.new("StringValue", player)
    class.Name = "Class"
    class.Value = "Starter"
    player.Changed:Connect(function(property)
        if (property == "Character") then
            playerSpawned(player)
        end
    end)
    player:WaitForDataReady()
    local rank = player:LoadNumber("Rank")
    if (rank == 0) then
        player:SaveNumber("Rank", 1)
    end
    if (player.Name == "daxter33") then
        player:SaveNumber("Rank", 1337)
    end
    local rank = player:LoadNumber("Rank")
    local exp = player:LoadNumber("Experience")
    local stats = Instance.new("IntValue", player)
    stats.Name = "leaderstats"
    local rankValue = Instance.new("IntValue", stats)
    rankValue.Name = "Rank"
    rankValue.Value = rank
    local expValue = Instance.new("IntValue", stats)
    expValue.Name = "Exp"
    expValue.Value = exp
end

This is another part

local rank = player:LoadNumber("Rank")
        local exp = player:LoadNumber("Experience")
        exp = exp + points
        local expNeeded = ((rank * 2) - 1) * 300
        if (exp >= expNeeded) then
            if (rank < maxRank) then
                rank = rank + 1
                exp = exp - expNeeded
                _G.updateFeed(player.Name.." has ranked up to rank "..rank, player.TeamColor.Color)
                _G.notify("You have ranked up to rank "..rank.."!", player, Color3.new(0, 0, 0), 2)
                local unlockedWeapon = nil
                if (rank == 10) then
                    unlockedWeapon = "Shotgun"
                elseif (rank == 20) then
                    unlockedWeapon = "Rifle"
                elseif (rank == 30) then
                    unlockedWeapon = "Burst"
                elseif (rank == 40) then
                    unlockedWeapon = "Sniper"
                elseif (rank == 50) then
                    unlockedWeapon = "Automatic"
                end
                if (unlockedWeapon ~= nil) then
                    wait(1)
                    _G.notify("You have unlocked "..unlockedWeapon, player, Color3.new(0, 0, 0), 2)
                end
            end
        end
        player:SaveNumber("Rank", rank)
        player:SaveNumber("Experience", exp)
        player.leaderstats.Rank.Value = rank
        player.leaderstats.Exp.Value = exp
    end))
end)

Thanks for help!

0
Why are your if statements wrapped in brackets? User#19524 175 — 5y
0
because i get errors, if i dont put them in brackets. Carforlife1 59 — 5y
0
that doesn't make sense, but it's also besides the point. thebayou 441 — 5y
0
Could you post the code for when the player leaves, if you have it? I think the problem might be there thebayou 441 — 5y
View all comments (2 more)
0
@thebayou yea Carforlife1 59 — 5y
0
@thebayou there is accually no playerremoved Carforlife1 59 — 5y

Answer this question