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
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.
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
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.
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.