I'm trying to get 2 server scripts to communicate with each other. Can I use :FireServer()
with a server-script? Is there a more efficient way to do this?
Ok, what you are trying to do is to make both of the server scripts communicate. But what you are doing, using FireServer from a RemoteEvent to communicate between these scripts is wrong. You should only be using a remote event when communicating between server and client. Try using a Bindable event to make communication between two of the same thing possible.
Here is an example. ServerScript1 is trying to give something to ServerScript2. Using BindableEvent, we can send it as an argument to ServerScript2 for it to print.
ServerScript1:
-- ServerScript 1 local Event = game.Workspace:WaitForChild("Event") local Arg1 = "Solution" wait(8) -- a buffer Event:Fire(Arg1)-- call event with an argument
ServerScript2:
-- ServerScript 2 local Event = game.Workspace.Event Event.Event:connect(function(Arg1) -- connect function to event print("Here is the "..Arg1.." !") -- prints out Arg1 end)
Pretty simple concept to understand, right?
Hoped this helped solve your question.
--| astrallife |--
Firstly, why do you want a split server script that calls another? Second, you can only use :FireServer() in a localScript, from Local to Server. Just combine both of the ServerScript into one
For example : So you can't do this
local remote = Instance.new("RemoteEvent") remote.Name = "HelloThereRemote" remote.Parent = game.ReplicatedStorage print("Hello there") remote:FireServer()
.
local remote = game.ReplicatedStorage:WaitForChild("HelloThereRemote") remote.OnServerEvent:Connect(function() print("Hi there") end)
Instead of that, do this
print("Hello there") print("Hi there")