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

Alternative to remote events for Server > Server use?

So I need a way to cleanly transfer data between two server scripts. I need something clean and similar to remote events. However, remote events are server > client or client > server only. Using them as so:

ServerScript1:

local event = script.Parent.Script2.SendRadioMessage

while true do
	event:FireServer("Some text", "some more text.")
	wait(0.5)
end

ServerScript2:

local sendRadioMessage = script:WaitForChild("SendRadioMessage")

sendRadioMessage.OnServerEvent:Connect(function(text1, text2)
	local stringValue = Instance.new("StringValue")
	stringValue.Parent = script.Parent.Folder1
	
	stringValue.Value = text1..": "..text2
end)

would result in "FireServer can only be called from the client."

Basically I need a way to transfer data between server scripts cleanly. Help?

1 comment

0

Of course, this is just an example.

2 answers

✓ Accepted answer

Commenting on @moo1210 answer, he's right.

Bindable Events

A BindableEvent is an object that has two important cross-communication properties. The first of the two is :Fire(...). This function will trigger BindableEvent. This is then detected by the next important property, .Event.

It is important to note that these can only communicate between scripts of the same scope (server to server or client to client)

First Script

BindableEvent:Fire(argument)

Second Script

BindableEvent.Event:Connect(function(argument)
 --code
end)

Bindable Function

A BindableFunction is very similar to a BindableEvent, however, it allows you to return a value back to the script that Invoked the function. One script will use the function :Invoke(...) in order to trigger the BindableFunction. The other script will detect this with its event: OnInvoke, however, something must be returned.

It is important to note that these can only communicate between scripts of the same scope (server to server or client to client)

First Script

BindableFunction:Invoke(argument)

Second Script

local something = BindableFunction.OnInvoke:Connect(function(argument)
 --code
 return something
end)

1 comment

0

Thx!

Bindablefunctions or bindableevents are just like remote functions or events, but there server - server and client - client. However, instead of xxxxxoninvoke or xxxxxfired, its just fired or oninvoke

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