attempt to call global 'NotifyAll' (a nil value)

I’m trying to configure the script below. The aim is that if a player who is set to either TEAM_MAYOR or TEAM_SPY dies, their team is reset to TEAM_CITIZEN and a Noficiation is printed to the server.

[lua]function MayorAssassination( ply, wep, killer )

if ply:Team() != TEAM_MAYOR then return end
if !killer:IsPlayer() then return end
ply:ChangeTeam(TEAM_CITIZEN, true)
NotifyAll(1,4,“The Mayor has been killed!”)

function JAssassination( ply, wep, killer)
if ply:Team() != TEAM_SPY then return end
if !killer:IsPlayer() then return end
ply:ChangeTeam(TEAM_SPY), true)
NotifyAll(1,4,“Joey has been killed!”)
end
hook.Add(“PlayerDeath”, “MayorAssassination”, MayorAssassination)
hook.Add(“PlayerDeath”, “JAssassination”, JAssassination)[/lua]

However, I am recieving this error.

attempt to call global 'NotifyAll' (a nil value)

Does anyone have any idea on how to fix this, and why this is being caused?

Thanks in advance.

Missing an end after line 6. Do you have NotifyAll defined?

EDIT:
And why are you doing two different hooks for the same thing? Just combine them into one function.

I’m an amateur, it just seems easier to make two that are separated. (neat)

I also noticed I added an unnecessary ‘)’ on line 11 after TEAM_SPY.

My new, updated version:
[lua]function MayorAssassination( ply, wep, killer )

if ply:Team() != TEAM_MAYOR then return end
if !killer:IsPlayer() then return end
ply:ChangeTeam(TEAM_CITIZEN, true)
NotifyAll(1,4,“The Mayor has been killed!”) end

function JAssassination( ply, wep, killer)
if ply:Team() != TEAM_SPY then return end
if !killer:IsPlayer() then return end
ply:ChangeTeam(TEAM_CITIZEN, true)
NotifyAll(1,4,“Joey has been killed!”) end
hook.Add(“PlayerDeath”, “MayorAssassination”, MayorAssassination)
hook.Add(“PlayerDeath”, “JAssassination”, JAssassination)[/lua]

How would I define NotifyAll?

This code works fine on its own, without NotifyAll being defined… It’s only when I add the second section that it breaks.
[lua]function MayorAssassination( ply, wep, killer )

if ply:Team() != TEAM_MAYOR then return end
if !killer:IsPlayer() then return end
ply:ChangeTeam(TEAM_CITIZEN, true)
NotifyAll(1,4,“The Mayor has been killed!”) end

hook.Add(“PlayerDeath”, “MayorAssassination”, MayorAssassination)[/lua]

[editline]12th December 2012[/editline]

[editline]12th December 2012[/editline]

Bump?

Would love to have this fixed and ready before I go to bed…


GAMEMODE:NotifyAll(1, 4, "Joey has been killed!");

Try doing that instead of just NotifyAll.


function Assassination( ply, wep, killer )
	if !killer:IsPlayer() then return end

  	if ply:Team() == TEAM_MAYOR then
			ply:ChangeTeam(TEAM_CITIZEN, true)
			GAMEMODE:NotifyAll(1, 4, "The Mayor has been killed!")
	elseif ply:Team() == TEAM_SPY then
		    ply:ChangeTeam(TEAM_CITIZEN, true)
		    GAMEMODE:NotifyAll(1, 4, "Joey has been killed!")
	end
end
hook.Add("PlayerDeath", "Assassination", Assassination)

I’m hoping this fixes your troubles. (It’s untested)

Thank you so much, this worked!

Thanks to Sudoxe also for making the effort to reply

for future references, global means a non-local function, you’ll see functions that have “local function” rather than just “function”, what happens is when you call a function that doesn’t exist local side, it’ll look for a global, if it can’t find a global, it’ll state theres no global function aka a “nil” value.