• Why is ent.Create causing an error?
    2 replies, posted
I'm having a problem with a script I'm making. The following code is causing an error that I don't quite understand... [code]local blowuprand = math.random(0,100) if (blowuprand / 100) <= self.SuicidePercent then if IsValid(self.Owner) then local gunexpl = ents.Create("env_explosion") local headindex = self.Owner:LookupBone("ValveBiped.Bip01_Head1") gunexpl:SetOwner(self.Owner) gunexpl:SetPos(self.Owner:GetPos()) gunexpl:SetKeyValue("iMagnitude", "10") gunexpl:Spawn() gunexpl:Fire("Explode", "", 0) end end[/code] It's called in the PrimaryAttack function. What is supposed to happen is, when the weapon is fired, there is a chance that it will explode, killing the player. The line 'ent.Create' is causing the following error, though: [code][ERROR] ...town/entities/weapons/weapon_ws_bootlegshotty/shared.lua:196: attempt to call field 'Create' (a nil value) 1. unknown - ...town/entities/weapons/weapon_ws_bootlegshotty/shared.lua:196[/code] Why? What's wrong with that code?
You're calling it on the client, you need to do something like [lua]if SERVER then local blowuprand = math.random(0,100) if (blowuprand / 100) <= self.SuicidePercent then if IsValid(self.Owner) then local gunexpl = ents.Create("env_explosion") local headindex = self.Owner:LookupBone("ValveBiped.Bip01_Head1") gunexpl:SetOwner(self.Owner) gunexpl:SetPos(self.Owner:GetPos()) gunexpl:SetKeyValue("iMagnitude", "10") gunexpl:Spawn() gunexpl:Fire("Explode", "", 0) end end end [/lua]
Oh, thanks! This whole lua thing is so weird to me :)
Sorry, you need to Log In to post a reply to this thread.