I am running this on nutscript and before I spawn a character I get a lua error
[ERROR] gamemodes/nutscript/gamemode/core/libs/cl_hud.lua:108: attempt to index a nil value
1. v - gamemodes/nutscript/gamemode/core/libs/cl_hud.lua:108
2. unknown - lua/includes/modules/hook.lua:84
Its because its trying to get the amount of money the character has but theres no character loaded. How do I makes this work
local money = LocalPlayer():getChar():getMoney()
[lua]
function hud()
local health = LocalPlayer():Health() or 0
local armor = LocalPlayer():Armor() or 0
local name = LocalPlayer():Name()
local stm = LocalPlayer():getLocalVar("stm", 0)
local money = LocalPlayer():getChar():getMoney() // THIS LINE HERE PROBLEM
draw.RoundedBox(15,0,ScrH() - 220,490,170,Color(234,94,0))
surface.SetDrawColor( 255, 255, 255, 255 )
//Borders
draw.RoundedBox( 0, 0, ScrH() - 70, 490, 5, Color(0, 0, 0) )
draw.RoundedBox( 0, 0, ScrH() - 210, 490, 5, Color(0, 0, 0) )
// Health
draw.RoundedBox(0, ScrW() - 1320, ScrH() - 90,100, 20, Color( 250, 0, 0, 100 ) )
draw.RoundedBox(0,ScrW() - 1320,ScrH() - 90,health,20,Color(255,0,0))
draw.DrawText( "Health", "TargetID", ScrW() - 1275, ScrH() - 90, Color( 0, 0, 0, 250 ), TEXT_ALIGN_CENTER )
//Armor
draw.RoundedBox(0, ScrW() - 1160, ScrH() - 90,100, 20, Color( 0, 0, 240, 100 ) )
draw.RoundedBox(0,ScrW() - 1160,ScrH() - 90,armor,20,Color(0,0,250))
draw.DrawText( "Armor", "TargetID", ScrW() - 1120, ScrH() - 90, Color( 0, 0, 0, 250 ), TEXT_ALIGN_CENTER )
//TEXT
draw.DrawText( "Time Played", "TargetID", ScrW() - 1275, ScrH() - 66, Color( 0, 0, 0 ), TEXT_ALIGN_CENTER )
draw.DrawText( "SeriousRP", "Cool", ScrW() - 100, ScrH() - 100, Color( 0, 0, 0, 250 ), TEXT_ALIGN_CENTER )
//name
draw.DrawText( "Name:", "TargetID", ScrW() - 1210, ScrH() - 180, Color( 0, 0, 0, 250 ), TEXT_ALIGN_CENTER )
draw.DrawText( name, "TargetID", ScrW() - 1135, ScrH() - 180, Color( 0, 0, 0, 250 ), TEXT_ALIGN_CENTER )
//money
draw.DrawText( "Money: $", "TargetID", ScrW() - 1210, ScrH() - 160, Color( 0, 0, 0, 250 ), TEXT_ALIGN_CENTER )
draw.DrawText( money, "TargetID", ScrW() - 1135, ScrH() - 160, Color( 0, 0, 0, 250 ), TEXT_ALIGN_CENTER )
//stam
draw.RoundedBox(0, ScrW() - 1010, ScrH() - 90,100, 20, Color( 0, 250, 0, 100 ) )
draw.RoundedBox(0,ScrW() - 1010,ScrH() - 90,stm,20,Color(0,250,0))
draw.DrawText( "Stamina", "TargetID", ScrW() - 970, ScrH() - 90, Color( 0, 0, 0, 250 ), TEXT_ALIGN_CENTER )
//test
surface.DrawCircle( ScrW() - 1298, ScrH() - 145, 55, Color(0,0,0,255) )
end
hook.Add("HUDPaint", "thehud", hud)
[/lua]
Where are you creating?
[lua]
getChar()
getMoney()
[/lua]
It may have something to do with those since its trying to "index" it. So something may be wrong with those functions.
[editline]10th June 2016[/editline]
Also, use Lua tags. I almost didn't see
[lua]
//THIS LINE HERE (is) PROBLEM
[/lua]
if LocalPlayer():getChar() then
--put the line here
end
[QUOTE=SirFrancisB;50493683]if LocalPlayer():getChar() then
--put the line here
end[/QUOTE]
If that is really what it says. That's not very smart :v:. Also that's not the function.
[lua]
function getChar()
--whatever YOU put
end
[/lua]
i am using nutscript and it gets lua errors when you first join because u dont have a character spawned yet.
Maybe use a if statement to check if the player's character has loaded and if it hasn't load the character or wait for the character to be loaded or make the function happen as the player chooses a character not before.
Set it to equal zero and there should be some hook which is ran when a character is created or ran, you should reset the money in there.
Sorry, you need to Log In to post a reply to this thread.