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

How Can I Implement, Death Resulting In Loss Of Gold And Experience?

Asked by 9 years ago

Ok so I am building a RPG game, and I am completely stumpted on how to create a script, where when you die you lose some Honor (Exp I can replace that out myself) depending upon the enemy that killed you & your Rank (Level). I also would like to do this with gold. Please help me out I WILL give credit, but if you were to use outside of my game I would like credit for the idea. Thank you, have a nice day.

2 answers

Log in to vote
0
Answered by 9 years ago

I'll explain the code in the script

game.Players.PlayerAdded:connect(function(Player) --When a player joins then do the following code...
    Player.CharacterAdded:wait() --Wait for the character to spawn
    wait(1) --Make sure everything loads
    Player.Character.Humanoid.Died:connect(function() --Once the character is loaded then find the humanoid and wait for it to die. Once it does, do the following code...
        if Player.leaderstats.Gold.Value >= 25 then --If the gold is bigger than or equal to 25 then do the following code...
            Player.leaderstats.Gold.Value = Player.leaderstats.Gold.Value-25 --Subtract 25 from the player's gold
        else --If the gold isn't bigger than or equal to 25 then do the following code...
            Player.leaderstats.Gold.Value = 0 --Make the player's gold 0.
        end --Close the If statement
    end) --Close the died event
end) --Close the PlayerAdded event

Enough detail for you?

0
I think it should be, I appriciate the time you put into this. UltimateRoGuy 0 — 9y
0
Where would I put this? Workshop or starter GUI? UltimateRoGuy 0 — 9y
0
ServerScriptService would work fine. lightpower26 399 — 9y
Ad
Log in to vote
3
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

Just so you know, this is very close to being against the rules of SH, especially since you didn't post any code to try and do this yourself.

The easiest way to do this is to call a function when the Player dies, giving it the Player and the Enemy that killed them, something like this:

function playerDied(Player, Enemy)
    if not Enemy then return end --Environmental deaths are 'free'
    local levelDifference = getLevel(Player) - getLevel(Enemy)
    if levelDifference <= -10 then return end --No loss for enemies greater than 10 levels above you.
    levelDifference = levelDifference + 10 --Convert this to a completely positive scale.

    setExperience(Player, getExperience(Player) - 10*levelDifference)
    giveGold(Player, -1*levelDifference)
end
0
Would I have to post this within the Starter GUI and or enemy which give off the said loss? UltimateRoGuy 0 — 9y
0
This code will not work on its own. Take a closer look at the functions I am using. You will have to either expand the code there or write your own functions for that. As for placement, I would suggest placing this in the ServerScriptService and calling from there when a player is killed. adark 5487 — 9y
0
Okay I will try thank you very much. Not very good at this though, mind if I friend you and ask occasional questions? UltimateRoGuy 0 — 9y
0
The Died event might also be of some use, so I suggest you search for that in the wiki. It's an event of player. GoldenPhysics 474 — 9y

Answer this question