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

There are errors in these scripts for my Heathbar gui, i am currently making an rpg. help?

Asked by 7 years ago
Edited 7 years ago

Leveling script

function onXPChanged(player, XP, level)
    if XP.Value>=level.Value * 20 then
        XP.Value = XP.Value - level.Value * 20
        level.Value = level.Value + 1
    end
end

function onLevelUp(player, XP, level)
    if player.Character~=nil then
        for i = 1,5 do
            local fireworks = Instance.new("Part")
            fireworks.Shape = "Ball"
            fireworks.formFactor = "Symmetric"
            fireworks.Reflectance = 0.1
           fireworks.Transparency = 0.5
        fireworks.CanCollide = false
            fireworks.Size = Vector3.new(2,2,2)
            fireworks.BrickColor = BrickColor.Random()
            fireworks.CFrame = player.Character.Head.CFrame + Vector3.new(0,2,0)
            fireworks.Parent = game.Workspace
            game:GetService("Debris"):AddItem(fireworks, 2)
            fireworks.Velocity = Vector3.new(math.random(-30,30),math.random(-30,30),math.random(-30,30))
        end
    end
end

function onPlayerRespawned(player)
    wait(5)
    player.Character.Humanoid.Health = player.leaderstats.Level * 10 + 100
    player.Character.Humanoid.MaxHealth = player.Character.Humanoid.Health
end

function onPlayerEntered(newPlayer)

newPlayer.CharacterAdded:connect(function(c) 
c.Humanoid.MaxHealth = newPlayer.leaderstats.Level.Value * 10 + 100
c.Humanoid.Health = c.Humanoid.MaxHealth
end) 

    newPlayer.leaderstats.XP.Changed:connect(function() onXPChanged(newPlayer.leaderstats, newPlayer.leaderstats.XP, newPlayer.leaderstats.Level) end)
    newPlayer.leaderstats.Level.Changed:connect(function() onLevelUp(newPlayer.leaderstats, newPlayer.leaderstats.XP, newPlayer.leaderstats.Level) end)

    newPlayer.Changed:connect(function (property)
        if (property == "Character") then
            onPlayerRespawned(newPlayer)
        end
    end)
end

game.Players.ChildAdded:connect(onPlayerEntered)

and the Datastore

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("IntValue") --Change points to whatever you want, unless you want to keep it
    xd.Name = "Level" --Name of the Points, or whatever name you changed it to
    xd.Parent = leaderstats
    xd.Value = 1

    local qe = Instance.new("IntValue") --Change wins to whatever you want, unless you want to keep it
    qe.Name = "XP" --Name of the Wins, or whatever name you changed it to
    qe.Parent = leaderstats
    qe.Value = 0

    local ss = Instance.new("IntValue") --Change wins to whatever you want, unless you want to keep it
    ss.Name = "Gold" --Name of the Wins, or whatever name you changed it to
    ss.Parent = leaderstats
    ss.Value = 0

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

    local storeditems = datastore:GetAsync(key)
    if storeditems then
        xd.Value = storeditems[1] --Value of the Points, change "points" if you changed line 10
        qe.Value = storeditems[2] --Value of the Wins, change "wins" if you changed line 14
        ss.Value = storeditems[3] --Value of the Wins, change "wins" if you changed line 14
    else
        local items = {xd.Value, qe.Value, ss.Value} --Change Points or Wins if you changed line 10 or 14
        datastore:SetAsync(key, items)
    end
end)

game.Players.PlayerRemoving:connect(function(player)
    local items = {player.leaderstats.Level.Value, player.leaderstats.XP.Value, player.leaderstats.Gold.Value} --Change Points or Wins if you changed line 10 or 14
    local key = "user-" .. player.userId

    datastore:SetAsync(key, items)
end)

and the HP

function _G.round(n)
return n - math.floor(n) >= 0.5 and math.ceil(n) or n - math.floor(n) < 0.5 and math.floor(n)
end

wait(0.5)
local char = script.Parent.Parent.Parent.Parent.Character
hum = char.Humanoid
Digit = script.Parent.Health.Digits
Round = (_G.round(hum.Health))
hum.Changed:connect(function()
script.Parent.Health.Frame.Size = UDim2.new(hum.Health/hum.MaxHealth,0,1,0)
Round = (_G.round(hum.Health))
RoundTwo = (_G.round(hum.MaxHealth))
Digit.Text = (Round.." / "..RoundTwo.." HP")
if hum.Health <= hum.MaxHealth*0.20 then
script.Parent.Health.Frame.BackgroundColor3 = Color3.new(255,0,0)
else
script.Parent.Health.Frame.BackgroundColor3 = Color3.new(0,255,0)
end
end)

0
Can you give us the errors and actually tell us what the problem is. User#16405 0 — 7y

Answer this question