|
| 27 Apr 2016 07:31 PM |
Hey hey! I was messing around and wanted to make a level script for the game i'm currently working on. At first I wanted it so that the players would get a certain amount of XP for killing other players and NPC. I didn't know how to do that so I opted to make it that you get XP after a certain amount of time and then after a certain amount of XP, you would level up. This is what I have so far.
function onPlayerEntered(newPlayer)
local stats = Instance.new("IntValue") stats.Name = "leaderstats"
local mins = Instance.new("IntValue") mins.Name = "level" mins.Value = 0 local mon = Instance.new("IntValue") mon.Name = "XP" mon.value = 0
mon.Parent = stats mins.Parent = stats stats.Parent = newPlayer
while true do wait(10) mon.Value = mon.Value + 5 end end
game.Players.ChildAdded:connect(onPlayerEntered)
What i'm having trouble with is making it so that after a certain amount of XP is earned, they would level up.
Should I use the if blank = blank then blank happens. Keep in mind i'm still a beginner scripter and don't understand much of everything |
|
|
| Report Abuse |
|
|
eRanged
|
  |
| Joined: 15 Jun 2013 |
| Total Posts: 9746 |
|
| |
|
|
| 27 Apr 2016 07:38 PM |
| Okay, if I do use that, how would I be able to make it so that after the XP reaches a certain amount, the level goes up? |
|
|
| Report Abuse |
|
|
eRanged
|
  |
| Joined: 15 Jun 2013 |
| Total Posts: 9746 |
|
|
| 27 Apr 2016 07:48 PM |
If XP == certainAmount then --LevelUp |
|
|
| Report Abuse |
|
|
|
| 27 Apr 2016 07:52 PM |
If XP == {50,100,150,200,250} then mins.Value = mins.Value + 1 end
would that work? |
|
|
| Report Abuse |
|
|
| |
|
vhgch
|
  |
| Joined: 26 May 2011 |
| Total Posts: 18 |
|
|
| 27 Apr 2016 08:50 PM |
| You should be checking if the player has reached a certain amount of exp each time you update the script. If they have reached that certain amount then you can reset their exp back to 0 and +1 to their level value. |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2016 03:11 PM |
| I would want to do it so that I could be it in a table in stead of having to write the code for each level, but once again. I don't know how to do that. |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2016 03:26 PM |
| create a loop if you use a table. while true do wait(.5) for i in pairs levelUp do if(levelUp[i] == userStat) user level++ end end |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2016 03:28 PM |
Scottmike is trolling, don't even pay attention to that idea....
-The [Guy] |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2016 03:29 PM |
| nah the code works. if infact the LevelUp is a table. |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2016 03:34 PM |
create a loop if you use a table. while true do wait(.5) for i in pairs levelUp do if(levelUp[i] == userStat) user level++ end end
"for i in pairs"
You need two variables. "for i, v in pairs"
"pairs levelUp do"
You need parenthesis. "pairs(levelUp) do"
The rest of your code isn't even Lua. You don't put the conditional statement in parenthesis. You need a "then" after your conditional statement. The incremental operator ++ doesn't even exist here.
if you weren't trolling, please screw your head back on straight, thanks.
-The [Guy] |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2016 03:35 PM |
you do not, learn how many loops there are in lua.
try it yourself if your do not believe me. |
|
|
| Report Abuse |
|
|
lupine
|
  |
| Joined: 24 Jun 2008 |
| Total Posts: 3561 |
|
|
| 28 Apr 2016 03:37 PM |
** pairs and ipairs doesn't require a second variable. If only 1 variable is present, you lose out on the index variable.
What he wrote was pretty effective psuedocode. I doubt he intended OP to copy + paste it into his script and go. |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2016 03:37 PM |
busy, if you cant script why are you here? he's not trolling, infact hes a damned good scripter.
#tix |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2016 03:46 PM |
Pseudocode, yes, that's perfectly acceptable. It didn't occur to me that's what he was trying to get across. "nah the code works. if infact the LevelUp is a table." Sounds like it was supposed to work in that form. Misunderstanding on my part.
Also, I didn't know it only required one variable. Live and learn.
I am hurt that you think I can't script though. I have helped probably around a thousand people here. I taught scripting sessions. I have written lots and lots of code, and my major is software engineering. I'm trying to help, that's the reason I'm here. No hard feelings meant by me toward anyone.
-The [Guy] |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2016 03:47 PM |
I apologize for going off of you, especially on a children's game. It just really annoys me when people say you can't do something, because they didn't do their homework.
|
|
|
| Report Abuse |
|
|
|
| 28 Apr 2016 03:48 PM |
example
our_table = {"Player","Who","Knows","Player1"}
print(our_table[1])
game.Players.ChildAdded:connect(function(player) print(player.Name) for i in pairs (our_table) do if(our_table[i] == player.Name) then print("it is true you are god"); end end end) |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2016 03:50 PM |
| and @ busy i am a computer science major, I dont think there is a such thing as a software engineer major. |
|
|
| Report Abuse |
|
|
| |
|
|
| 28 Apr 2016 03:59 PM |
| All you guys really did was confuse me O.o |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2016 04:02 PM |
Haha sorry about the confusion. Most people gave different ideas for how you can structure your leveling system. Most people suggested having experience, and when experience gets to a certain amount (the amount is based on how high a level you are), it will increase your level by one and set your experience back to 0. This is a pretty standard way of doing it. See the above posts for example code ideas.
-The [Guy] |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2016 04:07 PM |
learn how conditionals work, then you got your level up.
depending on how you want a user to level up is really up to you, it could be based on many factors, or just one. Depends on whether you like math or integers. |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2016 04:09 PM |
I don't understand the pairs.
What is their function and how would I use them?
I couldn't figure it out above. |
|
|
| Report Abuse |
|
|
|
| 28 Apr 2016 04:12 PM |
I hate everything involving math, and I know that'll be my downfall because you need math to code. That's why i'll never be good at coding.
I guess what I want would be something an intermediate would be able to learn. |
|
|
| Report Abuse |
|
|