Everything works fine until the the .OnServerEvent() in the module.
On the client I retrieve the type of morph, then on the server I weld the morph to the player.
What could be the issue?
local RunService = game:GetService("RunService")
local Remote = script.Remotes:WaitForChild("EquipMorph")
local MorphEquipped = false
local Morph = {}
local function Weld(Character, MorphType)
end
function Morph.Init()
if RunService:IsServer() then
local function Equip(Player, MorphType)
local Character = Player.Character
local Humanoid = Character:FindFirstChild("Humanoid")
if not MorphEquipped then
for _, Hats in ipairs(Character:GetChildren()) do
if Hats:IsA("Accessory") then
Hats:Destroy()
end
end
Character.Shirt.ShirtTemplate = MorphType.Shirt.ShirtTemplate
Character.Pants.PantsTemplate = MorphType.Pants.PantsTemplate
Weld(Character, MorphType)
MorphEquipped = true
end
end
Remote.OnServerEvent:Connect(Equip)
else
for _, Morphs in ipairs(workspace.Morphs:GetChildren()) do
for _, EquipMorphButton in ipairs(Morphs:GetChildren()) do
if EquipMorphButton.Name == "EquipMorph" then
EquipMorphButton.ProximityPrompt.Triggered:Connect(function()
print(EquipMorphButton.Parent)
Remote:FireServer(EquipMorphButton.Parent)
return
end)
end
end
end
end
end
return Morph
you are connecting to a function named “Equip” but theres no function named as that, if you are not gonna connect a function and create your own function you need to use
Maybe, you are getting this problem because the “MorphType” (or EquipMorphButton.Parent) only exists on the client. You could create a table which includes the info of the morph.
local RunService = game:GetService("RunService")
local Remote = script.Remotes:WaitForChild("EquipMorph")
local MorphEquipped = false
local Morph = {}
local function Weld(Character, MorphType)
end
function Morph.Init()
if RunService:IsServer() then
local function Equip(Player, MorphType)
local Character = Player.Character
local Humanoid = Character:FindFirstChild("Humanoid")
if not MorphEquipped then
for _, Hats in ipairs(Character:GetChildren()) do
if Hats:IsA("Accessory") then
Hats:Destroy()
end
end
Character.Shirt.ShirtTemplate = MorphType.Shirt.ShirtTemplate
Character.Pants.PantsTemplate = MorphType.Pants.PantsTemplate
Weld(Character, MorphType)
MorphEquipped = true
end
end
Remote.OnServerEvent:Connect(Equip)
else
for _, Morphs in ipairs(workspace.Morphs:GetChildren()) do
for _, EquipMorphButton in ipairs(Morphs:GetChildren()) do
if EquipMorphButton.Name == "EquipMorph" then
EquipMorphButton.ProximityPrompt.Triggered:Connect(function()
local NewMorph = EquipMorphButton.Parent
local MorphInfo = {
Shirt = {
ShirtTemplate = NewMorph.Shirt.ShirtTemplate
};
Pants = {
PantsTemplate = NewMorph.Pants.PantsTemplate
};
}
print(MorphInfo)
Remote:FireServer(MorphInfo)
return
end)
end
end
end
end
end
return Morph
If this is not issue, are you calling Morph.Init from both client and server?
@FunAsiK@ProxySFX I have a module which requires all my modules and calls the .Init() in all of them:
self.Modules = {}
if RunService:IsServer() then
for _, Module in next, ServerSciptService.ServerHandler.Modules:GetDescendants() do
if Module:IsA("ModuleScript") then
self.Modules[Module.Name] = require(Module)
end
end
else
for _, Module in next, ReplicatedStorage.Modules:GetDescendants() do
if Module:IsA("ModuleScript") and Module.Name ~= script.Name then
self.Modules[Module.Name] = require(Module)
end
end
end
local Success, Error = pcall(function()
for _, Modules in pairs(self.Modules) do
Modules.Init()
end
end)
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerSciptService = game:GetService("ServerScriptService")
local Encyclopedia = {}
Encyclopedia.__index = Encyclopedia
function Encyclopedia.Initiate()
local self = setmetatable({}, Encyclopedia)
self.Modules = {}
if RunService:IsServer() then
for _, Module in next, ServerSciptService.ServerHandler.Modules:GetDescendants() do
if Module:IsA("ModuleScript") then
self.Modules[Module.Name] = require(Module)
end
end
else
for _, Module in next, ReplicatedStorage.Modules:GetDescendants() do
if Module:IsA("ModuleScript") and Module.Name ~= script.Name then
self.Modules[Module.Name] = require(Module)
end
end
end
local Success, Error = pcall(function()
for _, Modules in pairs(self.Modules) do
print(Modules.Name)
Modules.Init()
end
end)
if Error then
warn(Error)
end
return self
end
return Encyclopedia
Entire script ^
I call .Initiate in both a local and server script
I meant to try printing the “Modules” itself. It is not an instance for it has no name, but it should be the required version of the item in self.Modules. So, you said that it printed nil. It’s printing nil because it’s not an instance, but I see that the modules were inserted into the table. I don’t see why it wouldn’t work.
you are saving value as [Module.Name] which means the key to that value will be Module.Name for example Module.Name is “someModule” so self.Modules["someModule"] will return that module
this had print nil because there is nothing saved for key named ["Name"]
I just thought of something. Maybe, the Morph.Init is running for the server and client at the same time, so the server doesn’t have enough time to connect the OnServerEvent before it is fired?