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

i have a problem with the points script i made can anyone help??

Asked by 5 years ago

ok so thi is the script

local level = 1
local exp = 0
local axp = 375

local InStudio = game:GetService("RunService"):IsStudio()

if not InStudio then
    level = game:GetService("DataStoreService"):GetDataStore("Levels")
    exp = game:GetService("DataStoreService"):GetDataStore("EXP")
    axp = game:GetService("DataStoreService"):GetDataStore("AXP")
end

function savedata(dataname, playerid, value)
    if InStudio then return end
    dataname:SetAsync(playerid, value)
end

game.Players.PlayerAdded:Connect(function(plr)
    local Strength = Instance.new("IntValue")
    Strength.Name = "Strength"
    Strength.Value = 1
    Strength.Parent = plr
    local pts = Instance.new("IntValue")
    pts.Name = "Points"
    pts.Value = 2
    pts.Parent = plr
    local levelz = Instance.new("IntValue")
    levelz.Name = "Level"
    levelz.Parent = plr
    local xpz = Instance.new("NumberValue")
    xpz.Name = "Experience"
    xpz.Parent = plr
    local xpn = Instance.new("IntValue")
    xpn.Name = "ExpNeeded"
    xpn.Parent = plr

    if not InStudio then
        xpn.Value = axp:GetAsync(tostring(plr.UserId)) or 375
        xpz.Value = exp:GetAsync(tostring(plr.UserId)) or 0
        levelz.Value = level:GetAsync(tostring(plr.UserId)) or 1
    else
        xpn.Value = axp
        xpz.Value = exp
        levelz.Value = level
    end

    xpz.Changed:Connect(function()
        if plr:WaitForChild("Experience").Value >= plr:WaitForChild("ExpNeeded").Value then
            levelz.Value = levelz.Value + 1
            xpn.Value = math.floor(xpn.Value * 2)
            xpz.Value = 0
            pts.Value = pts.Value + 2/2

            savedata(level, plr.UserId, levelz.Value)
            savedata(exp, plr.UserId, xpz.Value)
            savedata(axp, plr.UserId, xpn.Value)
        else
            savedata(level, plr.UserId, levelz.Value)
            savedata(exp, plr.UserId, xpz.Value)
            savedata(axp, plr.UserId, xpn.Value)
        end
        savedata(level, plr.UserId, levelz.Value)
        savedata(exp, plr.UserId, xpz.Value)
        savedata(axp, plr.UserId, xpn.Value)
    end)
end)

game.Players.PlayerRemoving:Connect(function(plr)
    savedata(level, plr.UserId, plr.Level.Value)
    savedata(exp, plr.UserId, plr.Experience.Value)
    savedata(axp, plr.UserId, plr.ExpNeeded.Value)
end)

and the problem is that the points you get when you level up the "points" get added to the starting value of the Points

something like this lvl 1 = 2 pts (because the player starts with this) lvl 2 = 4 pts (and thats what i meant) the pts or points is an IntValue

Answer this question