How to fix a lil error
trying to make a simple script... But it is breaking /advert TheTerrorist = { TEAM_DJ }
hook.Add( "PlayerSay", "TerrorStart", function( ply, text, public ) text = string.lower( text ) if ( text == "!terror" ) and ply:IsPlayer() and table.HasValue( TheTerrorist, ply:Team() ) then ply:Say( "/advert test", teamOnly==false ) else return false end
end )
error ----- [DarkRP] gamemodes/darkrp/entities/entities/darkrp_billboard/init.lua:50: attempt to compare nil with number
- callback - gamemodes/darkrp/entities/entities/darkrp_billboard/init.lua:50
- callback - addons/darkrp/gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua:17 3. RP_PlayerChat - addons/darkrp/gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua:78 4. unknown - addons/darkrp/gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua:142 5. Say - [C]:-1 6. v - addons/terror mod/lua/autorun/server/shared.lua:6 7. unknown - addons/darkrp/gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua:138
You're refering to a empty variable ofc? You can't refer to a variable you're creating
Replace ply:Say( "/advert test", teamOnly==false ) with ply:Say( "/advert test", false )
I think that should work.
EDIT:
And remove that 'else return false'
TheTerrorist = { 1 }
hook.Add( "PlayerSay", "TerrorStart", function( ply, text, public ) text = string.lower( text ) if ( text == "!terror" ) and ply:IsPlayer() and table.HasValue( TheTerrorist, ply:Team() ) then ply:Say( "/advert test", false ) end end )
Thats working for me..
TheTerrorist = { TEAM_DJ }
hook.Add( "PlayerSay", "TerrorStart", function( ply, text )
end )
-- Same error. What variable am i not refering too?
You're creating 'text' while you refering to 'text' making it a nil as your variable is nil and when you try and reference to that it simply will stay nil.
why does this work then?
hook.Add("PlayerSay" , "OpenTextCommand" , function(ply , text)
end)
You're on the update that's trying to create the billboard, which might have different arguments. The error that is occurring is happening in the actual billboard file itself.
ByHandsome Patrickat 4th of July 2016 16:37:25
why does this work then?hook.Add("PlayerSay" , "OpenTextCommand" , function(ply , text)if string.lower(text) == "!unbox" or string.lower(text) == "/unbox" thenply:ub_update_client()net.Start("ub_openui")net.Send(ply)endif string.lower(text) == "!unboxadmin" or string.lower(text) == "/unbox" thennet.Start("unboxadmin")net.Send(ply)endend)
Because he's never overwriting the actual text argument, he's just using it?
ByPatat 4th of July 2016 17:38:02
Because he's never overwriting the actual text argument, he's just using it?
The hook already gives him the "text" argument.
Edited It might be a bit of an odd suggestion, but you could change ply:Say( "/advert test", teamOnly==false ) to ply:ConCommand("Say","/advert","test"). Why? Because ply:Say() also seems to work on bots, this gives me the feeling it bypasses some of the other functions. Ply:CoCommand("Say","test") runs like if you would type something in your client console. It's just a suggestion, I don't know if it fixes the problem, but you might wanna give it a go.