Script prematurely stops after remote function call?

Making a script to change the player’s character model to another model that the player clicked. The server script works properly, just not the local script. When the server scripts remote function is completed, it stops when it returns back to the local script, it doesn’t progress after the initial local script’s invoke call.

The remote function I am working with is “charChange”

--Server Script
local rp = game.ReplicatedStorage
local charChange = script.Parent:WaitForChild("charChange")

charChange.OnServerInvoke = function(plr,rig)
	local health = rp.Health:Clone()
	local crig = rig:Clone()
	crig:SetPrimaryPartCFrame(plr.Character.PrimaryPart.CFrame)
	crig.Parent = workspace
	health.Parent = crig
	health.Disabled = false
	plr.Character = crig
	print("On server "..crig.Name)
	return crig
end

--Local Script 

local lp = game:GetService("Players").LocalPlayer
local mouse = lp:GetMouse()
local rp = game.ReplicatedStorage
local charChange = script.Parent:WaitForChild("charChange")
mouse.Button1Down:connect(function()
	local touch = mouse.Target
	if touch ~= nil then
		if touch.Parent:FindFirstChild("Humanoid") then
			local crig = charChange:InvokeServer(touch.Parent) -- Remote function gets called here
--The code stops here. Anything after this doesn't happen. 
			print("On Client "..crig.Name)
			local animate = rp.Animate:Clone()
			animate.Parent = crig
			animate.Disabled = false		
			local camera = game.Workspace.CurrentCamera
			camera.CameraType = "Follow"
			camera.CameraSubject = crig:FindFirstChild("Head")
		end
	end
end)

This is what my workspace looks like

scriptlocation

This is because a remote function yields and stops the code on purpose for a return call, and doesn’t run until the function returns something

It returns “crig”, and when playing the script, the serverscript runs through all the code of the remote function, up to the “print” function. I don’t think it’s yielding at all since the function completed everything.

1 Like

oh then you can try and printing it and see:

print(charChange:InvokeServer(touch.Parent))

Where is the remote function located?

In both scripts you have the function indexed as “script.Parent.charChange”

scriptlocation

This is what the heiarchy looks like

Doing this prints nothing. It seems like it will complete the server script but refuses to go back to the local script.

Try putting the remote function in ReplicatedStorage and server script in ServerScriptService. Use local charChange = game:GetService("ReplicatedStorage"):WaitForChild("charChange") to reference the remote in both scripts.

I was suggested this earlier elsewhere. It came with the same results.

put remoteFunction in repStorage and shouldn’t characterChangerServer be in ServerScriptService instead of StarterGui :thinking:, I don’t think you should put the characterChangerServer script in StarterGui, put it in ServerScriptService