Getting invalid left-hand side of assignment near '=' error.
7 replies, posted
Hi, I am making an NPC that once the user presses E on the NPC a Frame pops up with a few buttons with different health values, so far I only have made one button and while writing the code to give the user 100 health I get the error mentioned in the title, here is the cl_init file I am getting the error in:
include("shared.lua")
local player = LocalPlayer()
function ENT:Initialize()
self.AutomaticFrameAdvance = true
end
function ENT:Draw()
self:DrawModel()
end
net.Receive("healthNPCUsed", function(len, ply)
local frame = vgui.Create("DFrame")
frame:SetSize(1000,720)
frame:Center()
frame:SetVisible(true)
frame:MakePopup()
function button1Pressed()
if player:Health() == 100 then
chat.AddText(Color(255, 0, 0), "You already have 100 health")
end
if player:Health() < 100 then
player:Health() = 100
end
end
local button1 = vgui.Create("DButton", frame)
button1:SetPos(10, 40)
button1:SetSize(200, 45)
button1:SetText("Get 100 Health")
button1.DoClick = button1Pressed
button1.Paint = function(self, w, h)
draw.RoundedBox(6, 0, 0, w, h, Color(255, 255 ,255))
end
end)
The error is happening in the if statement where I am checking if the health is less than 100. Any help would be appreciated!
'player:Health() = 100' is invalid syntax. You should use Entity/SetHealth.
player is nil. LocalPlayer() is nil until the player is *actually created*
put the local player = LocalPlayer(); in the net.Receive function
After doing that I am getting a new error, this time in the gmod console:
[ERROR] lua/entities/basicentity/cl_init.lua:21: Tried to use a NULL entity!
1. Health - [C]:-1
2. DoClick - lua/entities/basicentity/cl_init.lua:21
3. unknown - lua/vgui/dlabel.lua:234
I'm not sure why?
You have to set the health serverside.
But the Health() class is both serverside and clientside.
yes the class, but not the function to set the health to something. if that would be clientside, so many people could exploit that to give themself billions of life or near god mode
Does not mean you can set it clientside (which you cant)
You'll have to networking for that.
Sorry, you need to Log In to post a reply to this thread.