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.
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?
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