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

Giving players 10 cash per 5 kills?

Asked by 6 years ago
Edited 6 years ago

How would this work...

I have this...

But I'm wondering if there would be a shorter way to do this

local plr = game.Players.LocalPlayer

plr.stats.Kills.Changed:connect(function()
    if plr.stats.Kills.Value == 5 then
        plr.stats.Coins.Value = plr.stats.Coins.Value + 10
    end
end)

1 answer

Log in to vote
0
Answered by
T0XN 276 Moderation Voter
6 years ago
Edited 5 years ago

Hi Arxk,

Good start, but if you want to award the player with 10 coins for EVERY 5 kills they get, then you'd want to store the number of kills in a variable. Whenever the player gets five kills, the variable would be reset to 0 again and the process would repeat. It may sound hard to accomplish, but I think the code will speak for itself.

The error you made is where you check if the number of kills the player has is EQUAL to 5, in which case the player would only be awarded coins when they have 5 kills.

I'd assume you want plr.stats.Kills.Value to display the total kills the player has, so that is why I still use that variable in the code.

local plr = game.Players.LocalPlayer

local killCount = 0
local totalKills = plr.stats.Kills.Value
local coins = plr.stats.Coins.Value

totalKills.Changed:Connect(function()
    killCount = killCount + 1
    if killCount == 5 then
        coins  = coins  + 10
        killCount = 0
    end
end)

Hope this helped!

0
Thanks! User#19328 0 — 6y
0
No problem. If you liked my answer then please accept it! T0XN 276 — 6y
Ad

Answer this question