What Am I Doing Wrong (Lua Not Working)

In single-player, I try to do lua_run_cl ply:SetHealth(11) and it doesn’t work.

I tried doing ply:SetWalkSpeed(750) on a server too and it didn’t work.

I am not sure what I am doing, I made a script and did lua_openscript_cl setHealth.lua

setHealth.lua:



ply:SetHealth(999999999)


And it didn’t work… I thought maybe it didn’t know who ply was but I tried print(ply:GetName()) and it said my name…

Any help for a noob?

You need to define ply.

Example(Clientside):
[lua]
local ply = LocalPlayer()
[/lua]

2 things,

first - ply is undefined, it’s only valid when you make it valid. If you’re working clientside you might want to use LocalPlayer(), if you’re doing stuff server side you might use Entity(1).

second - lua_openscript_cl opens a client side script, even though SetHealth is a shared function, it’ll do nothing clientside

I just tried doing this in the sethealth.lua:
[lua]
local ply = LocalPlayer()
ply:SetHealth(999999999)
[/lua]

and it didn’t work still…

Read my post…

AHH! Thank you so much, I didn’t realise lua_openscript_cl opened it clientside… come to think of it, it’s a bit obvious. Thanks again though!