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

[SOLVED] How do I pass data with events?

Hello!

I'm trying to pass an object from a normal script to a localscript which I wasn't able to do since I'm not sure how to get the sent object with the localscript. I looked at this developer link about remote functions and events, but it was very unclear to me, and I wasn't able to find out how.

eventName:FireAllClients(script) -- should send the script object

Now for the localscript:

eventName.OnClientEvent:Connect(functionName) -- when the event is fired, it connects to the function, but how do I receive the script object from this localscript?

3 comments

0

You cannot send Object's as arguments. You can receive arguments in the form of parameters: function foo(param1, param2)

0

See https://developer.roblox.com/en-us/articles/Function to understand more about arguments & parameters.

0

I'm basically asking if the script gets stored as a variable?

2 answers

Hello, 7z99! The problem with passing objects with FireClient() is that they might not be rendered yet (StreamingEnabled) or that the object isn't accessable with LocalScripts. For example, you cannot fire a script through with FireClient(). You also can't fire things in ServerStorage or ServerScriptService as they are only accessible to the server. For more information go to the Server-Client Model on the Roblox Developer Hub. Make sure to accept this answer if it hepls you.

3 comments

0

I know this, however it should be possible as the player would never be far enough away from the part for it to not be rendered.

0

To simplify, I'm just asking if the "script" object gets stored as a variable, and if so, how do I access or modify the variable/

0

You cannot modify the script variable on the client, however, you can on the server. The player can be far enough from the part for it to not be rendered if you have Streaming Enabled on. (Property of Workspace.)

I ended up solving it.

Normal Script:

eventName:FireAllClients(script)

LocalScript:

eventName.OnClientEvent:Connect(functionName)

function(argument1) -- brackets are where the arguments go
	--pretend this does stuff lol
end

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