Error: "attempt to call global 'Local Player' <a nil value>


LocalPlayer() exists clientside only. You can run it with lua_run_cl or lua_openscript_cl in your Garry’s mod’s console.
It doesn’t exist serverside, eg. when you lua_run or lua_openscript.

if client.IsDetective and client:IsDetective() then; I’m not sure how the rolechecking works, but I’m pretty sure checking if the client is a detective two different ways like this will not work.

This is being run on Server-Side if client doesn’t exist.

He’s checking that IsDetective is not Nil and then actually checking the result of it.

But wouldn’t IsDetective be a meta function, so it’s always defined?

Assuming you’re running this client side, it’s failed because it’s storing LocalPlayer() as soon as the script is loaded, so the local player doesn’t actually exist yet, just replace client with LocalPlayer() in your script:

[lua]function red()
self.EmitSound(“Sound_Path/file.wav”, 100, 100)

if LocalPlayer().IsDetective and LocalPlayer():IsDetective() then
    self:SetColor(Color(255, 0, 0, 255))


However, it’s quite clearly a client side command because you are setting the colour of something, which would set for everyone on the server, it appears you only want to set something red on the client.

On another side note, ‘self’ isn’t defined…