• Any help?
    9 replies, posted
Hello I just tried to make some fun here, but i cant get this code working [code] local frame = vgui.Create("DFrame") frame:SetTitle("Test Addon") frame:SetSize(1280,720) frame:Center() frame:SetVisible(true) frame:MakePopup() local Mixer = vgui.Create("DColorMixer", frame) Mixer:SetPos(10,40) Mixer:SetPalette( true ) Mixer:SetAlphaBar( true ) Mixer:SetWangs( true ) Mixer:SetColor(Color(30,100,160)) local ply = LocalPlayer() local plyh = ply:Health() local nick = ply:Nick() local Button = vgui.Create("DButton", frame) Button:SetPos(10,300) Button:SetText("I like this color a lot!") Button:SetSize(200,40) function Button:DoClick() if plyh <= 50 then end timer.Simple( 5, function() ply:ChatPrint(nick) end ) end [/code]
[QUOTE=Denvist;50436845]Hello I just tried to make some fun here, but i cant get this code working [code] -snip- [/code][/QUOTE] What is it meant to do? And whats the error?
You need to end the 'if' statement.
By the looks of it you want to put [LUA]function Button:DoClick() if plyh <= 50 then timer.Simple( 5, function() ply:Kill() end ) end end[/LUA]
This is the error: [code] [ERROR] lua/menu.lua:18: function arguments expected near 'local' 1. unknown - lua/menu.lua:0 [/code]
[QUOTE]LocalPlayer():Health[/QUOTE] I think this might be your problem.
As Bubbie said, the syntax is incorrect. You also need to close the if statement inside the function. You should always check if an entity is valid if you're planning to delay an action, this way you avoid errors. Lastly, you can't call Player:Kill() from client, either call the console command "kill" or network the server so that it kills you.
[QUOTE=Bubbie;50438060]I think this might be your problem.[/QUOTE] i tried to change [CODE] local plyh = LocalPlayer():Health ----> local plyh = ply:Health [/CODE] Code updated. I tried to change the code, but still arent working and still giving same error [CODE] [ERROR] lua/menu.lua:18: function arguments expected near 'local' 1. unknown - lua/menu.lua:0 [/CODE] I just searched on Gmod wiki and found out that Player:Kill is server and then I tried to change ply:Kill ----> ply:Nick because Nick is both so i set it to print, but still arent working :d But sill getting same error.
LocalPlayer():Health()
[QUOTE=McDunkable;50438159]LocalPlayer():Health()[/QUOTE] Code Updated. Well, you have just fixed my problem. Now i just changed ply:Kill -----> ply:Nick instead because Kill is server as i found out. Thanks a lot. Now it works
Sorry, you need to Log In to post a reply to this thread.