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

How can I make a leaderstat or leaderboard take away health if it is low?

Asked by
jm34 7
9 years ago

So I'm making a RPG game, and I have Gold, Level, and XP, but I added my own other leaderstat called "Ki" and what it does is whenever you use a energy weapon like a "Ki Blast" it would lower your ki. But whenever It shoots it lowers the Ki and Ki regens but if you keep clicking the ki goes into negative numbers and so you can shoot infinitely. I need to make it so it stops at 0 or if you go into negative numbers it subtracts health.

Here is the RPG Script:

function onXPChanged(player, XP, level, c)
    if XP.Value>=level.Value * 100 then
        XP.Value = XP.Value - level.Value * 50
        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 = 0
            fireworks.formFactor = "Symmetric"
            fireworks.Size = Vector3.new(1,1,1)
            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
    local m = Instance.new("Hint")
    m.Parent = game.Workspace
    m.Text = player.Name .. " has powered up!"
    wait(3)
    m.Parent = nil
end

function onLevelUp(player, XP, level)
    wait(0.1)
    player.Character.Humanoid.Health = player.leaderstats.PwrLvl.Value * 100 + 100
    player.Character.Humanoid.MaxHealth = player.leaderstats.PwrLvl.Value * 100 + 100

--[[
    local stuff = player.Backpack:GetChildren()
    wait(5)
    for i = 1,#stuff do
        local name = stuff[i].Name
        if game.Starterpack:findFirstChild(name)==nil then
            stuff[i]:Clone().Parent = player.Backpack
        end
    end
--]]
end

function onPlayerEntered(newPlayer)
    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"

    local xp = Instance.new("IntValue")
    xp.Name = "XP"
    xp.Value = 0

    local level = Instance.new("IntValue")
    level.Name = "PwrLvl"
    level.Value = 1

    local g = Instance.new("IntValue")
    g.Name = "Zeni"
    g.Value = 10

    local c = Instance.new("IntValue")
    c.Name = "Ki"
    c.Value = 100

    c.Parent = stats

    stats.Parent = newPlayer 

    xp.Parent = stats
    level.Parent = stats
    c.Parent = stats
    g.Parent = stats

    stats.Parent = newPlayer

    xp.Changed:connect(function() onXPChanged(newPlayer, xp, level) end)
    level.Changed:connect(function() onLevelUp(newPlayer, xp, level) end)

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

game.Players.ChildAdded:connect(onPlayerEntered)

while true do
players= game.Players:GetChildren() 
for i = 1, #players do 
if players[i].leaderstats.Ki.Value ~= 100 then
players[i].leaderstats.Ki.Value = players[i].leaderstats.Ki.Value + 1
end 
end 
wait(0.3) 
end

--My original attack script and your version. ( I couldn't get yours to work)

function onButton1Down(mouse)
game.Players.LocalPlayer.leaderstats.Ki.Value = game.Players.LocalPlayer.leaderstats.Ki.Value - 20
end


function onS(mouse)
mouse.Button1Down:connect(function() onButton1Down(mouse) end)
end
script.Parent.Selected:connect(onS)

Yours

script.Parent.Selected:connect(onS)

game.Players.LocalPlayer.leaderstats.Ki.Value = Ki

function onButton1Down(mouse)
    local KiToRemove = 5
    if Ki >= KiToRemove then
        Ki = Ki - KiToRemove
        function onS(mouse)
    mouse.Button1Down:connect(function() onButton1Down(mouse) end)
end
    script.Parent.Selected:connect(onS)
    end
end
0
Where is the code where it removes ki? TheDeadlyPanther 2460 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

You have not given me any of the code that actually removes Ki, but this how you do it:

function Attack1()
    local KiToRemove = 5
    if Ki >= KiToRemove then
        Ki = Ki - KiToRemove
        -- Attack code
    end
end
0
Thank you so much! I will try to add this to the script. jm34 7 — 9y
0
Oh the code to remove it was in a tool. jm34 7 — 9y
0
I just added it to my code for the question jm34 7 — 9y
Ad

Answer this question