My remote function is supposed to spawn object from Replicated Storage to the workspace by pressing an UI. However its not working somehow and it doesn’t yield me an error?
--Local
local RS = game:GetService("ReplicatedStorage")
local Event = RS:WaitForChild("Events")
local SpawnFunction = Event:WaitForChild("SpawnUnit")
local Gui = script.Parent
for i,v in pairs(Gui.UnitList.Frame:GetChildren()) do
if v:IsA("ImageButton") then
v.Activated:Connect(function()
print("Spawned " .. v.Name)
SpawnFunction:InvokeServer(v.Name)
print("Successfully spawned")
end)
end
end
--Module
local Unit = {}
local RS = game:GetService("ReplicatedStorage")
local Event = RS:WaitForChild("Events")
local SpawnFunction = Event:WaitForChild("SpawnUnit")
function Unit.SpawnUnit(unit)
local tower = RS.Units:FindFirstChild(unit)
local UnitClone = tower:Clone()
UnitClone.Parent = workspace.Unit
end
SpawnFunction.OnServerInvoke = Unit.SpawnUnit
return Unit
A remote function Returns something, this means that it will pause the script that called it (in this case the local script) until that something is returned.
So you only use it when you NEED to confirm that the event has been completed, and you are going to use the reference from the script that called it.
So to answer your question, yes it would work because the server would take over and handle the management of the unit, not the client.
I tried remote events now inside module script but it still doesnt work. And it also doesn’t give me any output too beside the “Successfully spawned” and “Spawned … Name” Print
yes. i fill the “unit” parameter by the button names which the code will find the object in the units folder
been 1 hour and still cant find a solution welp
Now that i put it on Server script. I got an error
OnServerInvoke is a callback member of RemoteFunction; you can only set the callback value, get is not available.
What does that mean?
oh and fyi all im doing is basically making so if you place a TextButton (GUI) an object spawn from the server side