'Then' expected near '='

I made a script that, when you spawn as “Male09”, your health gets set to 5. I got this error:


 
lua\autorun\health_script.lua:1: 'then' expected near '='


Here is my code:


if mdl = models/player/group01/male_09 then
Player:SetHealth(5)

Be aware that this is my first lua script EVER.

When asking if an object is equal to another object you have to use “==”. You’ll figure out why later on.

Alright, did that and it gave me another error. I fixed it by adding an “end” to the end of the code.
Got another error from that:


lua\autorun\health_script.lua:1: attempt to perform arithmetic on global 'models' (a nil value)

You have to surround strings with " or '.


if mdl == "models/player/group01/male_09.mdl" then
Player:SetHealth(5)
end


I forgot about that. Thanks, I will test it and report any more bugs I find.

[editline]07:32PM[/editline]

Strange. I found no errors, yet the script doesn’t work. I have tried killing myself and typing “lua_openscript health_script” in console. Nothing works.

Judging from the errors above, your script is in autorun, and yet you are opening it in lua.


lua_openscript autorun/health_script

We cant really help you till you give us all the code, also @ Banana Lord its pointless yes, but it shoulding cause any problems to him…

Thats the whole code right there.

[lua]
function maleCheck(ply)
if (ply:GetModel() == “models/player/group01/male_09.mdl”) and ply:IsPlayer() then do
ply:SetHealth(5) – if the model is male_09 then it sets the player’s health
end
end
end

hook.Add(“PlayerSpawn”, “CheckModel”, maleCheck ) – when the player spawns, the function’s called
[/lua]

run it, set your model to male_09, kill yourself
if it doesn’t work the first time kill yourself again

-yours truly

I’ve already tried that.

And it works?

No.

Uh that’s strange because it worked for me

Quick question:

How can you use ply:CreateRagdoll in a lua script?

I’ve never used that function before, but I think it just creates a clientside ragdoll at a defined position.

oh and ply is just an argument, not pre-defined. You’d need to define it as a player before you can use it

Yeah, its serverside but creats the ragdoll for players clientside, so it may fall in different places for each client.

Woahhhh, this is so easy it hurts my brain <:B