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

Gold and EXP will only stay at 10 and not go anything past 10?

Asked by 7 years ago
Edited 7 years ago

when you kill a mob in the rpg, it gives 5 gold and 5 xp but no matter how many times you kill something or how much xp and gold you get, it will not go past 10. please help here is the script

local datastore = game:GetService("DataStoreService"):GetDataStore("MyRPGDataStore") --Call "GameStore" whatever you like


game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("IntValue")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local xd = Instance.new("IntConstrainedValue")
    xd.Name = "Level"
    xd.Parent = leaderstats
    xd.Value = 1
    xd.MaxValue = workspace:FindFirstChild("GameSettings").MaxLevel.Value
    xd.MinValue = 0

    local qe = Instance.new("IntConstrainedValue")
    qe.Name = "EXP"
    qe.Parent = leaderstats
    qe.Value = 0
    xd.MaxValue = workspace:FindFirstChild("GameSettings").MaxEXP.Value
    xd.MinValue = 0

    local ss = Instance.new("IntConstrainedValue")
    ss.Name = "Gold"
    ss.Parent = leaderstats
    ss.Value = 0
    xd.MaxValue = workspace:FindFirstChild("GameSettings").MaxGold.Value
    xd.MinValue = 0

    local key = "user-" .. player.userId

    local storeditems = datastore:GetAsync(key)
    if storeditems then
        xd.Value = storeditems[1]
        qe.Value = storeditems[2]
        ss.Value = storeditems[3]
    else
        local items = {xd.Value, qe.Value, ss.Value}
        datastore:SetAsync(key, items)
    end

    while wait(120) do
        local stats = player:FindFirstChild("leaderstats")
        local aitems = {stats.Level.Value, stats.EXP.Value, stats.Gold.Value}
        local key = "user-" .. player.userId
    datastore:SetAsync(key, aitems)
    end
end)

game.Players.PlayerRemoving:connect(function(player)
    local stats = player:FindFirstChild("leaderstats")
    local items = {stats.Level.Value, stats.EXP.Value, stats.Gold.Value}
    local key = "user-" .. player.userId
    datastore:SetAsync(key, items)
end)

1
Show us the code that awards gold & exp, this code is fine. TheDeadlyPanther 2460 — 7y
0
I used to have the same problem, Try redoing the order you put the Xp's Values in, Example: Instead of Value,MaxValue,MinValue try MaxValue,MinValue,Value This might not work but it's worth a shot :/ starblasto 43 — 7y
0
leaderstats is supposed to be a model, not an IntValue. cabbler 1942 — 7y

Answer this question