|
| 20 Feb 2012 03:50 PM |
OutPut:Workspace.Leaderboard:16: attempt to index global 'Stats2' (a nil value)
local C = script.Config --Config holds all the things you need to edit local CN = C.CurrName --(Currency Name) local LN = C.LName --(Level Name) local XN = C.ExpName --(Experiance Name) local Mult = C.Mult --Multiplier (For HP Advancment up) local CK = C.CurrKey --(Currency Key) local LK = C.LKey --(Level Key) local XK = C.ExpKey --(Experiance Key)
function checkLevelUp(lvl,exp,plr) if exp.Value >= (lvl.Value*(lvl.Value*7)) then exp.Value = exp.Value - (lvl.Value*(lvl.Value*7)) lvl.Value = lvl.Value +1 plr.Character.Humanoid.MaxHealth = (100+(Stats2.Value*Mult.Value)) plr.Character.Humanoid.Health = plr.Character.Humanoid.MaxHealth end end
game.Players.PlayerAdded:connect(function(plr) local Stats = Instance.new("IntValue",plr) Stats.Name = "leaderstats" local Stats2 = Instance.new("IntValue",Stats) Stats2.Name = LN.Value --This is the Level Stat Stats2.Value = 1 local Stats3 = Instance.new("IntValue",Stats) Stats3.Name = XN.Value --This is the EXP Stat local Stats4 = Instance.new("IntValue",Stats) Stats4.Name = CN.Value --This is the Currency Stat plr.CharacterAdded:connect(function(char) plr.Character.Humanoid.MaxHealth = (100+(Stats2.Value*Mult.Value)) plr.Character.Humanoid.Health = plr.Character.Humanoid.MaxHealth end) plr.Chatted:connect(function(msg) if string.lower(msg) == "save/" then c,d = pcall(function() plr:SaveNumber(LK.Value,Stats2.Value) plr:SaveNumber(CK.Value,Stats4.Value) plr:SaveNumber(XK.Value,Stats3.Value) end) if c then local Mess = Instance.new("Message",plr.PlayerGui) Mess.Text = "You have saved your game!" wait(2) Mess:remove() else local Mess = Instance.new("Message",plr.PlayerGui) Mess.Text = "The game has failed to save. Please contact the game maker." wait(2) Mess:remove() end elseif string.lower(msg) == "load/" then c,d = pcall(function() Stats2.Value = plr:LoadNumber(LK.Value) if Stats2.Value == 0 then Stats2,Value = 1 end Stats3.Value = plr:LoadNumber(XK.Value) Stats4.Value = plr:LoadNumber(CK.Value) end) if c then local Mess = Instance.new("Message",plr.PlayerGui) Mess.Text = "You have loaded your game!" wait(2) Mess:remove() else local Mess = Instance.new("Message",plr.PlayerGui) Mess.Text = "The game has failed to load. Please contact the game maker." wait(2) Mess:remove() end end end) while true do wait() checkLevelUp(Stats2,Stats3,plr) end end) |
|
|
| Report Abuse |
|
|
| |
|
crazyblox
|
  |
| Joined: 16 Mar 2008 |
| Total Posts: 6139 |
|
| |
|
crazyblox
|
  |
| Joined: 16 Mar 2008 |
| Total Posts: 6139 |
|
|
| 20 Feb 2012 04:26 PM |
Nvm, i skimmed the script also i have my own problem :C |
|
|
| Report Abuse |
|
|
C0D3Y
|
  |
| Joined: 24 Jul 2010 |
| Total Posts: 1692 |
|
|
| 20 Feb 2012 04:27 PM |
| You locally defined stats2 in a function, but this means you can only index it within that function. |
|
|
| Report Abuse |
|
|
Cakins
|
  |
| Joined: 23 Jul 2009 |
| Total Posts: 307 |
|
|
| 20 Feb 2012 04:27 PM |
function checkLevelUp(lvl,exp,plr) if exp.Value >= (lvl.Value*(lvl.Value*7)) then exp.Value = exp.Value - (lvl.Value*(lvl.Value*7)) lvl.Value = lvl.Value +1 plr.Character.Humanoid.MaxHealth = (100+(lvl.Value*Mult.Value)) plr.Character.Humanoid.Health = plr.Character.Humanoid.MaxHealth end end |
|
|
| Report Abuse |
|
|
Cakins
|
  |
| Joined: 23 Jul 2009 |
| Total Posts: 307 |
|
|
| 20 Feb 2012 04:29 PM |
| The problem wasn't not defining the variable, it was the fact that you used what the variable equaled rather than the variable itself. |
|
|
| Report Abuse |
|
|
|
| 20 Feb 2012 05:06 PM |
I got one more problem
OutPut:Players.Player.PlayerGui.Main Gui.Left / Total.Script:2: attempt to index field 'Character' (a nil value)
while true do PlayerHealth = script.Parent.Parent.Parent.Parent.Character.Humanoid.Health PlayerMaxHealth = script.Parent.Parent.Parent.Parent.Character.Humanoid.MaxHealth wait(.1) script.Parent.Text = ("" .. math.floor(PlayerHealth) .. " / " .. math.floor(PlayerMaxHealth) ) end |
|
|
| Report Abuse |
|
|