-
What do you want to achieve? Keep it simple and clear!
I’m making a game, and in it when you press a button it should invoke the server via remoteFunction to spawn the player and then return the model they were spawned as. -
What is the issue? Include screenshots / videos if possible!
Although the code completely runs on the server-side, so the player model is created and their character is set, it never returns the remoteFunction to the localScript so it can continue (this has been confirmed via print statements)
Local script, stored in starterGui:
script.Parent.MouseButton1Click:Connect(function()
-- Get services
local click = game:GetService("SoundService").Button
local guiHandler = require(game.ReplicatedStorage.Modules.GuiHandler)
local player = game:GetService("Players").LocalPlayer
click:Play()
local operator = game.ReplicatedStorage.Remotes.SpawnPlayer:InvokeServer(script.Parent)
print("This should print - but doesn't")
guiHandler.setCam(Enum.CameraType.Custom, workspace.CurrentCamera, operator.Humanoid)
end)
Relevant portion of server script, stored in serverScriptService:
remotes.SpawnPlayer.OnServerInvoke = function(player, item)
-- Get in-game objects
local chosenOperator = game.ServerStorage.Operators[item.Name]
local character = player.Character
local localScripts = {}
print(script.Name.. ": Play button variables collected")
-- Clone important objects into model
for index,item in pairs(game.StarterPlayer.StarterCharacterScripts:GetChildren()) do
if item:IsA('LocalScript') then
table.insert(localScripts,item:Clone())
else
item:Clone().Parent = chosenOperator
end
end
-- Set model properties
character.Health:Clone().Parent = chosenOperator
table.insert(localScripts,character.Animate:Clone())
chosenOperator.Parent = workspace
chosenOperator.Name = " "
player.Character = chosenOperator
for index2,item2 in pairs(localScripts) do
item2.Parent = localScripts.Character
end
print(script.Name.. ": Player model created")
-- Spawn player in map
local spawnPoints = workspace.SpawnPoints
local parts = {spawnPoints.Spawn1,spawnPoints.Spawn2,spawnPoints.Spawn3,spawnPoints.Spawn4}
local target = parts[math.random(#parts)]
player.Character.HumanoidRootPart.CFrame = target.CFrame
print(script.Name.. ": Player spawned in map")
print(script.Name.. ": Play button script completed")
return chosenOperator
end
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I looked on the developer hub, youtube, and even read guides on remoteFunctions to ensure I was using them right. None of it helped.