Door Buying Error

So when I start my game I get this error and my gamemdoe goes back to sandbox

gamemodes esting\gamemode\init.lua:348: function arguments expected near ‘and’

[LUA]
function Doorowning( ply )

local trace = ply:GetEyeTrace()

if( trace.Entity:IsValid() and trace.Entity:IsOwnable and ply:GetPos():Distance( trace.entity:GetPos() ) < 100 then -- Line 348

	if(trace.Entity:OwnedBy( ply ) ) then
		trace.Entity:UnOwn( ply )
		Notify( ply, 1, 4, "You've unowned this door.")
	else
	
		if trace.Entity:IsOwned() then
		Notify( ply, 1, 4, "This Door is allready owned!")
		return end
		
		if not trace.Entity:IsOwned() then
		trace.Entity:Own( ply )
		Notify( ply, 1, 4, "You have bought this door for 50$" )
		ply:AddMoney( -50 )
		end
	end
end

end
concommand.Add(“buydoor”, Doorowning)
[/LUA]

I don’t really know whats wrong if someone could give me some help that would be great.

Edit:

I’m getting a new error after I changed what Banana Lord told me to change

gamemodes esting\gamemode\init.lua:348: attempt to index field ‘entity’ (a nil value)

You missed a ‘)’-bracket on line 5.

( () ()( () )

I still get the same error

I’m a big Lua noob, but shouldn’t it be
[lua] if( trace.Entity:IsValid() and trace.Entity:IsOwnable()[/lua]

on the error line

I’m getting a new error after I changed what you told me to.

gamemodes esting\gamemode\init.lua:348: attempt to index field ‘entity’ (a nil value)

trace.entity is not the same as trace.Entity

Pay attention to case-sensitivity and syntax and you’ll find that you run into a lot less problems :wink:

-snip-

[editline]05:24PM[/editline]

Ah, it Works thanks for the help everyone!

How would I bind f2 to this? I tried doing it the way the wiki does it but that didn’t work.

[lua]-- serverside
function GM:ShowTeam(pl)
umsg.Start(“OpenIt”, pl)
umsg.End()
end

-clientside
usermessage.Hook( “OpenIt”, somefunction)[/lua]

This isn’t clientside though.

then use

[lua]function GM:ShowTeam(pl)
Doorowning(pl)
end
[/lua]

That works, Thanks again!

No problem :wink: