Invoke Server not working for client

So i wanna make a spawning unit system using remote function. But in client when i pressed the button they doesn’t works and not giving me any errors


-- MODULE SCRIPT (Server script Service)
function Unit.SpawnUnit(player,NewUnit)
	local allowed = Unit.Check(player,NewUnit)
	
	if allowed then
		local SpawnedUnit = RS.Units[NewUnit]:Clone()
		SpawnedUnit.Parent = workspace.Unit
		for i,object in ipairs(SpawnedUnit:GetDescendants()) do
			if object:IsA("MeshPart") or object:IsA("Part") or object:IsA("UnionOperation") then
				object.CollisionGroup = "Units"
			end
		end
		
		
		return SpawnedUnit
	else
		return false
	end
	
end

SpawnFunction.OnServerInvoke = Unit.SpawnUnit


return Unit

Local script:

-- LOCAL

local spawnedtower = nil
ButtonGui.Activated:Connect(function()
				
				if not db then
					spawnedtower = ButtonGui.Name
					
					local allowed = requestFunc:InvokeServer(spawnedtower)
					
					if allowed then
						local spawned = spawnUnitFunc:InvokeServer(spawnedtower) 
						if spawned then
							print("spawned unit")
						end
					end
					

The ModuleScript has to be required to bind the event together. ModuleScripts don’t run unless they’re required. Instead, place the OnServerInvoke line on a ServerScript.

so i add another server script in server script service, Require the module and connect the OnServerInvoke from Serverscript to Module script?

Yep, or you can just require the module, but it’s not recommended if you have multiple scripts requiring the same thing.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.