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

Problems With RemoveEvents, Help?

Asked by
Vezious 310 Moderation Voter
8 years ago

Server Script

Events.Notifier:FireClient(("Intermission ("..script.Intermission.Value..")"),255,255,255)

Local Script

Notifier.OnClientEvent:connect(function(message,V1,V2,V3)

Output For Server Script: 16:25:28.193 - Unable to cast value to Object

Sorry, Its my first day using RemoteEvents

2 answers

Log in to vote
2
Answered by 8 years ago

No problem. Here's something you should know every time you're working with remote events / functions.

Hidden default argument

In both remote events / functions, there is a hidden first argument that's returned to the server that represents the client that's invoking the remote. ScriptGuider actually gives a good example of this in his remote event example place, which you can check out here:

http://www.roblox.com/games/286802910/Remote-event-example

Or go to his profile and edit his "Remote event example" game.

So, now knowing this, we should always identify this hidden argument to avoid error and confusion. Let's give an example from the server's perspective:

Server:

-- Let's say the script is inside the remove event

local Remote = script.Parent

-- Remote event's have an event called "OnServerEvent", which fires the given function when the
-- remote is invoked by the client.

-- DefaultPlayer (the first argument) is ALWAYS the client.
Remote.OnServerEvent:connect(function(DefaultPlayer, Arg1, Arg2, Arg3)
    print(DefaultPlayer, Arg1, Arg2, Arg3)
end)

Now, if we attempted to fire this event from the client, we would do so like this:

Client:

local Remote = workspace:WaitForChild'RemoteEvent'

-- We use "FireServer" on the remote (from a local script) to invoke the remote from the server.
-- Remember, the default argument is the client, so these 3 values we return fill the role of
-- our "Arg1", "Arg2", and "Arg3" variables from above.

Remote:FireServer("I'm","a","remote")

Output from server: I'm a remote

How to fire a listening client, from a server

Now, sometimes we wan't to do the opposite. Sometimes we want to have listening clients, waiting on server instructions. This can be achieved through "FireClient", and works about the same way. The first argument is the player we're going to invoke (assuming they have an event listening), and the rest of the arguments passed are whatever.

So:

Server:

-- Server script
-- Again, we'll assume the script is in the remote

local Remote = script.Parent

wait(10)

Remote:FireClient(game.Players.Player1, "Hello there")

Client:

-- Let's assume the script's name is 'Script'
local Remote = workspace.Script.RemoveEvent

-- Instead of OnServerEvent, we use OnClientEvent.
-- The first argument we passed from the server does not apply here.
Remote.OnClientEvent:connect(function(Args)
    print(Arg)
end)

Client output: Hello there

Or, we could use "FireAllClients" from the server, to fire every listening client with the OnClientEvent function. Like this:

Server:

local Remote = script.Parent

-- Obviously, we don't need a player for first argument
-- since this will fire all listening clients.

Remote:FireAllClients('Hello there')

Hope this helped. If you still have questions, let me know.

Ad
Log in to vote
0
Answered by 8 years ago

The first argument of FireClient has to be the player on which the event is being invoked.

If you want to fire it for every player, you can use FireAllClients which does not require the player to be supplied as an argument.

local intermissionMsg = "Intermission ("..script.Intermission.Value..")"
Events.Notifier:FireAllClients(intermissionMsg,255,255,255)

Answer this question