I am trying to do this type of communication in a Module script placed in ServerScriptService:
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Morph = {}
function Morph.Init()
local self = setmetatable({}, Morph)
self.Remote = Instance.new("RemoteEvent")
self.Remote.Name = "EquipMorph"
self.Remote.Parent = ReplicatedStorage.Events
self.MorphEquipped = false
if RunService:IsServer() then
self:WeldToCharacter()
else
self:GetMorphType()
end
return self
end
function Morph:WeldToCharacter()
self.Remote.OnServerEvent:Connect(function(Player, MorphType)
end)
end
function Morph:GetMorphType()
self.Remote:FireServer(EquipMorphButton.Parent)
end
return Morph
However, it is not working!! Would anyone be able to help me with this problem?
1 Like
Could you be more descriptive about your problem? Also,
function Morph:GetMorphType()
self.Remote:FireServer(EquipMorphButton.Parent)
end
You can not fire the server from the server.
1 Like
So I was wondering if I could have one module handle communication between Client-Server.
On the client, it retrieves the morph type and sends the name of the morph to the server.
EquipMorphButton.Parent.Name -- the name of the morph
On the server, it welds the specified morph to the player who activates the event.
Would it make sense to move the module to ReplicatedStorage? If so, how would I provide the remote event to the server?
Yes, but this is an impractical way of doing this. To make the event you can make it and parent it to replicated storage, then get the remote event with the scripts instead of making the remote event with the scripts.
Instead of moving the module script to replicated storage you can also just do
ReplicatedStorage.Remote:FireServer(EquipMorphButton.Parent)
in a localscript. Since this is the only thing needed by the client, it wouldn’t make sense to require the entire module script on the client only to use the
Morph:GetMorphType()
function.