Not getting error but code not working

So I am made a script and its not working?? Its pretty self explained :smiley: but it isnt working :frowning:

CLIENT SIDE



	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


[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)

You didn’t have to make a new thread for this.

This is completly different

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.

Well, how are you testing this? I hope you’re not testing this in a server, alone. lol

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.

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()




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



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.

Instead of using chat.AddText use :PrintMessage

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.

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]

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 :




function Test()

	for k,v in pairs(player.GetAll()) do

		v:ChatPrint("ASDSAD")

	end

end



How do you expect to be helped then?

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)

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:



--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)


Edit:
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.