Attempt to index local 'sender' ( a nil value ) for shop script
3 replies, posted
[lua]
function GiveaDeagle(sender, command, arguments)
if sender:Money_Get() >= 400 then
sender:Give("weapon_interloper_deagle")
sender:Money_Take( 400 )
return true
else
return false
end
end
concommand.Add("GiveMeAGun" , GiveaDeagle() )[/lua]
At line 40, it's giving me this error "attempt to index local 'sender ' ( a nil value) ". I'm trying to let players buy weapons and then have their money taken away but after 2 hours of just messing code around, i'm stuck on this. My brain is fried at the moment, can anyone please help me solve this?
[QUOTE=Cookieeater;34449905][lua]
function GiveaDeagle(sender, command, arguments)
if sender:Money_Get() >= 400 then
sender:Give("weapon_interloper_deagle")
sender:Money_Take( 400 )
return true
else
return false
end
end
concommand.Add("GiveMeAGun" , GiveaDeagle() )[/lua]
At line 40, it's giving me this error "attempt to index local 'sender ' ( a nil value) ". I'm trying to let players buy weapons and then have their money taken away but after 2 hours of just messing code around, i'm stuck on this. My brain is fried at the moment, can anyone please help me solve this?[/QUOTE]
Remove the "()" from "GiveaDeagle" in the concommand.Add.
Many thanks. I also need to have the trader tell the player doesn't have enough money if the player tries to purchase something that's too expensive. How would I modify this code to trigger the chat.AddText function? Here is what I have at the moment.
[lua]
PistolButton.DoClick =
function()
if RunConsoleCommand("GiveMeAGun") == false then
chat.AddText(Color(255,255,128), "Merchant: ",Color(255,255,255), "Guns don't grow on trees, sweety. You'll need more money for that one." )
end
end
[/lua]
You'd have to do something along the lines of [lua]function()
If (LocalPlayer():Money_Get() < <Money Here>) then
--Chat.AddText Shit
end
end[/lua]
Sorry, you need to Log In to post a reply to this thread.