Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

event / function ignoring first argument ?

Basically I have a code that gets fired to a localscript in all players. The speaker / player argument is used to make sure the event is recieved by the correct reciever, and the "allow" argument is a boolean value used for later code. (Don't think about that part).

This is the :FireEvent Script

game.ReplicatedStorage.AllowDisallowPresent:FireClient(speaker, true)

This is the reciever / localscript

game.ReplicatedStorage.AllowDisallowPresent.OnClientEvent:Connect(function(player, allow)
	if not player.Name == game.Players.LocalPlayer.Name then return end

Error:

attempt to index boolean with 'Name'

My thought is that it skips the player argument or switches it with the allow parameter. I have tried searching it up on google, although i didnt find a clear answer.

Sincerely, ItsMeMathe

1 answer

Alright so, the issue lies in the Firing, and Receiving signal.

Let me give you a bit of correct Syntax:

Event:FireClient(plrInstance, tuple args)

Event.OnClientEvent:Connect(function(received tuple args)

With that, you can tell that the way of the firing is wrong. You need to specify which player to fire the Event to. Unless you want to fire it to all the Players then: Event:FireAllClients(tuple args)

And OnClientEvent doesn't put the player instance as their first argument, they just went straight into the tuple args that the Server fired to the Client.

I'm sorry if the explanation wasn't clear, but let me try providing an example:

Server:

Event:FireClient(plr, tuple)

or:

Event:FireAllClients(tuple)

Client: (Correct way)

Event.OnClientEvent:Connect(function(tuple)
	-- bla bla
end)

Sources:

DevHub: RemoteEvent

ScriptingHelpers: Issue with transaction

DevHub: FireAllClients

DevHub: FireClient

This discussion is preserved as it was. New answers, comments, and votes are closed.