Invoke Client while there is a ServerScript Manager?

I’m trying to make a Unit Spawner but there is something wrong, When i click the spawn unit button it doesnt spawn his type in the team spawn.

Here it is the Script Parts that i have added.

Client (button)

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.RemoteEvents.SpawnUnit:Invoke("Blue","Rifler")
end)

Server (UnitSpawnManager)

function SpawnUnit(team,unittype)
	if team == "Blue" then
		local UnitChoosen = TeamUnits.BlueTeam.unittype:Clone()
		UnitChoosen.Parent = workspace
		UnitChoosen.HumanoidRootPart.Position = workspace.World.TeamBases.blubase.spawnunit + Vector3.new(0, 5, 0)
	end
end

ReplicatedStorage.RemoteEvents.SpawnUnit.OnInvoke = SpawnUnit

Reply to this post to see if you have any fixes.

I think you meant to use a RemoteFunction and call InvokeServer(). You are referencing a bindable function based on your syntax. Ensure the remote function is in fact, a remote function. Then, Use InvokeServer() and OnServerInvoke(). Client - Server communication requires remote functions, not a bindable function.

Changed Code

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.RemoteEvents.SpawnUnit:InvokeServer("Blue","Rifler")
end)
function SpawnUnit(playerInvoked,team,unittype)
	if team == "Blue" then
		local UnitChoosen = TeamUnits.BlueTeam.unittype:Clone()
		UnitChoosen.Parent = workspace
		UnitChoosen.HumanoidRootPart.Position = workspace.World.TeamBases.blubase.spawnunit + Vector3.new(0, 5, 0)
	end
end

ReplicatedStorage.RemoteEvents.SpawnUnit.OnInvoke = SpawnUnit

I have tried this and my units aren’t still spawning.

I did read what you said but it didnt work.

Send me the new code and a screenshot of where the Remote Function is in your explorer.

image

(Blue Team is a experimental, thats why there is only a blue team classes)

sorry for bad spelling

Add a print to SpawnUnit() to make sure the connection is made. Can I also see the code?

You mean the whole ReplicatedStorage and the basic gui?

Okay here it is:

SpawningUnits.rbxl (32.6 KB)

OnServerInvoke contains a function, it is not connected. I would do this:

local ReplicatedStorage = game.ReplicatedStorage

local RemoteEvents = ReplicatedStorage.RemoteEvents
local SpawnUnit = RemoteEvents.SpawnUnit
local TeamUnits = ReplicatedStorage.TeamUnits

ReplicatedStorage.RemoteEvents.SpawnUnit.OnServerInvoke = function(playerInvoked,team,unittype)
	if team == "Blue" then
		local UnitChoosen = TeamUnits.BlueTeam.unittype:Clone()
		UnitChoosen.Parent = workspace
		UnitChoosen.HumanoidRootPart.Position = workspace.World.TeamBases.blubase.spawnunit + Vector3.new(0, 5, 0)
	end
end

The function will not be reusable, but it will establish that connection. OnServerInvoke has to be EQUAL to a function, it’s not a signal like .OnServerEvent.

Understandable, Maybe i did something wrong while writing the script.

We all make mistakes! If you get it to work, make sure to mark the solution so readers know!

You should use onServerInvoke and InvokeServer to Invoke the function.

Seems like its still not working

Send your updated code. Did you connect the ServerInvoke like I said to? Also, use prints to see where the error occurs.

I have connected the client with ServerInvoke tho…

game.ReplicatedStorage.RemoteEvents.SpawnUnit:InvokeServer("Blue","Rifler")

Let me see how you’re receiving that server invocation. I want to make sure your syntax is right.

I checked the output but no errors except for my plugin being script deprecated. But thats not the case.

Also its not printing it so it’s not executing the script.

Understood, so can I see the code to help you identify the error?

local ReplicatedStorage = game.ReplicatedStorage

local RemoteEvents = ReplicatedStorage.RemoteEvents
local SpawnUnit = RemoteEvents.SpawnUnit
local TeamUnits = ReplicatedStorage.TeamUnits

ReplicatedStorage.RemoteEvents.SpawnUnit.OnServerInvoke = function(playerInvoked,team,unittype)
	if team == "Blue" then
		local UnitChoosen = TeamUnits.BlueTeam.unittype:Clone()
		UnitChoosen.Parent = workspace
		UnitChoosen.HumanoidRootPart.Position = workspace.World.TeamBases.blubase.spawnunit + Vector3.new(0, 5, 0)
		warn("Successfully Added Unit")
	end
end

i added warn on the place of print tho. if you wanna change it, you can.

First error. UnitChosen should be

TeamUnits.BlueTeam:FindFirstChild(unittype):Clone()

You are referencing the literal “unittype” not the value of the variable by using a period.