• Not getting error but code not working
    19 replies, posted
So I am made a script and its not working?? Its pretty self explained :D but it isnt working :( CLIENT SIDE [CODE] if callerType == 1 then for k,v in pairs(player.GetAll()) do for i,p in pairs(JobsForMedic) do if v:getDarkRPVar("job") == p then if v != LocalPlayer() then chat.AddText(callerMessage) end end end end end [/CODE] [editline]10th August 2017[/editline] I am trying to make it where when callerType equals 1 and a table has a job which the player is using then the player will get a message (callerMessage)
[img]http://i.imgur.com/mLelZmS.png[/img] You didn't have to make a new thread for this.
This is completly different
[QUOTE=ZeroToHero;52558824]So I am made a script and its not working?? Its pretty self explained :D but it isnt working :( CLIENT SIDE [CODE] if callerType == 1 then for k,v in pairs(player.GetAll()) do for i,p in pairs(JobsForMedic) do if v:getDarkRPVar("job") == p then if v != LocalPlayer() then chat.AddText(callerMessage) end end end end end [/CODE] [editline]10th August 2017[/editline] I am trying to make it where when callerType equals 1 and a table has a job which the player is using then the player will get a message (callerMessage)[/QUOTE] if v != LocalPlayer()? So you want it to run on everyone but the person calling it, and in essence have it run on no one?
I want to run it on everyone but the person calling it, yes.
[QUOTE=ZeroToHero;52558904]I want to run it on everyone but the person calling it, yes.[/QUOTE] Well, how are you testing this? I hope you're not testing this in a server, alone. lol
[QUOTE=ZeroToHero;52558904]I want to run it on everyone but the person calling it, yes.[/QUOTE] Have you tried debugging it? Making sure it runs? After every check, put in a print to chat or something and make sure every line is running.
If there are 2 players in the game it sends me (The user using the menu I made) the message I sent 2 times. If there are 1 it sends me it once.
[QUOTE=ZeroToHero;52558951]If there are 2 players in the game it sends me (The user using the menu I made) the message I sent 2 times. If there are 1 it sends me it once.[/QUOTE] Could you please reword that whole sentence?
I made a dframe. If I press button 1 then press send it will set callerType to 1 and run the function SendMessage(). I also have a table named JobsForMedic{} that has jobs in it such as "Citizen". This is whats in SendMessage() [CODE] if callerType == 1 then for k,v in pairs(player.GetAll()) do for i,p in pairs(JobsForMedic) do if v:getDarkRPVar("job") == p then if v != LocalPlayer() then chat.AddText(callerMessage) end end end end end [/CODE] If I am alone in a server and press the first button then press send I get the message 1 time : "Message" if I am in a server with 2 players and I press button 1 then send I get the message 2 times "Message; Message" and the other player doesnt get anything. The other player is supposed to get the message but he/she isnt.
[QUOTE=ZeroToHero;52558979]I made a dframe. If I press button 1 then press send it will set callerType to 1 and run the function SendMessage(). I also have a table named JobsForMedic{} that has jobs in it such as "Citizen". This is whats in SendMessage() [CODE] if callerType == 1 then for k,v in pairs(player.GetAll()) do for i,p in pairs(JobsForMedic) do if v:getDarkRPVar("job") == p then if v != LocalPlayer() then chat.AddText(callerMessage) end end end end end [/CODE] If I am alone in a server and press the first button then press send I get the message 1 time : "Message" if I am in a server with 2 players and I press button 1 then send I get the message 2 times "Message; Message" and the other player doesnt get anything. The other player is supposed to get the message but he/she isnt.[/QUOTE] Instead of using chat.AddText use [URL="https://wiki.garrysmod.com/page/Player/PrintMessage"][U]:PrintMessage[/U][/URL]
Tried that, and just print. I think it might be some code above or below. idk
You're trying to send a chat message to someone else's chat? You cannot do that clientside.
[QUOTE=TylerB;52559020]You're trying to send a chat message to someone else's chat? You cannot do that clientside.[/QUOTE] I disagree. When I used a hook for a chat check, in my amateur moment, I forgot to check for the local player. Of course, this file ran on everyone's client. However, you are right because he is running on everyone and checking if they're the local player, and then denying them. I laugh. To the OP: instead of checking for LocalPlayer, check for the person you don't want to get the chat message. Otherwise, I dunno how you're getting the messege, if you're denying every local player, you shouldn't be getting any messeges. [editline]10th August 2017[/editline] [QUOTE=ZeroToHero;52559010]Tried that, and just print. I think it might be some code above or below. idk[/QUOTE] Post your whole file.
Nah its 400 lines long + dont want any stealing but I ran this as a test with me and my friend and he isnt getting it : [CODE] function Test() for k,v in pairs(player.GetAll()) do v:ChatPrint("ASDSAD") end end [/CODE]
[QUOTE=ZeroToHero;52559087]dont want any stealing[/QUOTE] How do you expect to be helped then?
[QUOTE=ZeroToHero;52559087]Nah its 400 lines long + dont want any stealing but I ran this as a test with me and my friend and he isnt getting it : [CODE] function Test() for k,v in pairs(player.GetAll()) do v:ChatPrint("ASDSAD") end end [/CODE][/QUOTE] If you can't figure out these problems yourself, and based on the history of your questions, no one is going to want to steal your code.
Its client sided and hes trying to run it on other players, network it to server then resend it to the clients using chat.AddText or v:SendLua (on server)
[QUOTE=JacobsReturn;52559875]Its client sided and hes trying to run it on other players, network it to server then resend it to the clients using chat.AddText or v:SendLua (on server)[/QUOTE] He doesn't even have to resend it to clients, he can just print it to every player that needs it serverside.
The nesting of the first snippet of code is ridiculous. You should really narrow that down. If you'd bother to explain what you (guys) are trying to do step by step, it'd be a little easier to understand. What I got from this was: 1. Player(1) presses a button on a menu. 2. Gets sent to the server. (Via a net message I'd assume?) 3. Gets re-broadcasted (again, via a net message?) to every player and goes through the original snippet you posted. A better way to go about this would be like: 1. Player presses button. 2. Sent to server, goes through the checks - in a more efficient manner. 3. Run player:ChatPrint(msg) serverside instead of sending it via another net and clogging net space with garbo. Example: [code] --Client Button.DoClick = function() net.Start("CL_Message") --Write whatever data is needed (idk if there was any) net.SendToServer() end --Server util.AddNetworkString("CL_Message") net.Receive("CL_Message", function(len,ply) --Read Data --Run through the checks v:ChatPrint() -- Chat Print end) [/code] [B]Edit:[/B] For further explanation, basically it's not working because you're trying to send a message from a client directly to other clients. The only way that it'll work is if you send it from the server or use the method I provided above.
Sorry, you need to Log In to post a reply to this thread.