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

How to increase leaderstat points by opponents Level?

Asked by 7 years ago
Edited 7 years ago

Hello! Below I have my kill script, where Points/EXP is awarded to the player who defeats the other player. What I'd like to do is increase the value of the Points/EXP awarded, by the defeated opponents "Level" on their leaderstats.

example - if player defeats a Level 1 opponent they receive 5 points, if player defeats a Level 2 opponent, they receive 10 points, etc.

Hitting a bit of a wall on that one I've tried adding several different lines, that all seem to result in "is not a valid" with humanoid and the like. Any help suggested would be appreciated. :) Thank you!

The script below works fine, when I add the extra math for the opponent's Level, it goes bad.

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(char)
        local hum = char:WaitForChild('Humanoid')
        hum.Died:connect(function()
            local tag = hum:FindFirstChild('creator')
            if tag ~= nil then
                if tag.Value ~= nil then
                    local leaderstats = tag.Value:FindFirstChild('leaderstats')
                    if leaderstats ~= nil then
                        leaderstats.Points.Value = leaderstats.Points.Value + 5 
                        leaderstats.EXP.Value = leaderstats.EXP.Value + 35
                    end
                end
            end
        end)
    end)
end)
0
Just to clarify: You're asking to increase the amount of points based on they're rank? For example [Rank 1 - 5 Points a kill], [Rank 1 - 10 Points a kill] ? Tradesmark 65 — 7y
0
*Rank 2 Tradesmark 65 — 7y
0
Yes! If a player defeats a player at Rank 4, I want them to receive more points than if they defeated someone at Rank 1 Never2Humble 90 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Create a new variable for math. Try using this. It will be based off the players EXP.

For example;

Player 1>EXP 25> Receives 42 Points.

Player 2>EXP 100> Receives 167 Points.

Player 3>EXP 350> Receives 583 Points.

Player 4>EXP 800> Receives 1,333 Points.

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(char)
        local hum = char:WaitForChild('Humanoid')
        hum.Died:connect(function()
            local tag = hum:FindFirstChild('creator')
            if tag ~= nil then
                if tag.Value ~= nil then
                    local leaderstats = tag.Value:FindFirstChild('leaderstats')
                    if leaderstats ~= nil then
                        local points = 5 -- How many raw points the kill is worth.
              local rank = leaderstats.EXP.Value / 3 -- You can adjust this value to change how dramatic the bonus is.
                        leaderstats.Points.Value = leaderstats.Points.Value + rank  * points -- Applying the math.
                        leaderstats.EXP.Value = leaderstats.EXP.Value + 35
                    end
                end
            end
        end)
    end)
end)
0
That's a neat script, but doesn't address what I need. I need it to where if a player defeats a level 2 opponent, they receive more EXP/Points than if they defeat a level 1 opponent. =( Never2Humble 90 — 7y
0
But you didnt' specify your path for their level! Tradesmark 65 — 7y
0
That's what I need help with, I'm not sure of the correct code to put in for that. Never2Humble 90 — 7y
0
Found the solution with your help. Thanks! :) leaderstats.Points.Value = leaderstats.Points.Value + player.leaderstats.Level.Value * 2 leaderstats.EXP.Value = leaderstats.EXP.Value + player.leaderstats.Level.Value * 20 Never2Humble 90 — 7y
0
Yes! Tradesmark 65 — 7y
Ad

Answer this question