Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

event / function ignoring first argument ?

Asked by 2 years ago

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

Log in to vote
0
Answered by 2 years ago

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

Ad

Answer this question