generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Script error

Previous Thread :: Next Thread 
blackhalodude is not online. blackhalodude
Joined: 16 Jun 2010
Total Posts: 412
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
blackhalodude is not online. blackhalodude
Joined: 16 Jun 2010
Total Posts: 412
20 Feb 2012 04:24 PM
anyone?
Report Abuse
crazyblox is not online. crazyblox
Joined: 16 Mar 2008
Total Posts: 6139
20 Feb 2012 04:25 PM
Define Stats2.
Report Abuse
crazyblox is not online. 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 is not online. 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 is not online. 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 is not online. 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
blackhalodude is not online. blackhalodude
Joined: 16 Jun 2010
Total Posts: 412
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image