How can move my local script to server?

I’m making a VR game where parts that act like hands follow the users hand position. I have working code but it doesn’t seem to want to work on the server where it errors on the remote event fire stage and says cam.CFrame does not exist. I do really need help on remote eventing it to the server. Thanks.

Local Script:

game:GetService(“RunService”).RenderStepped:Connect(function()
if(isUsingVR) then
local hands = workspace:WaitForChild(game.Players.LocalPlayer.Name…“Hands”)
if hands then
local RightHand = hands.R
local LeftHand = hands.L
local HeadScale = 1
local Cam = workspace.CurrentCamera
Cam.HeadScale = HeadScale

		local cfRH = vrService:GetUserCFrame(Enum.UserCFrame.RightHand)
		local cfLH = vrService:GetUserCFrame(Enum.UserCFrame.LeftHand)
		local camCF = Cam.CFrame
		
		RightHand.CFrame = (camCF*CFrame.new(cfRH.p*HeadScale))*CFrame.fromEulerAnglesXYZ(cfRH:ToEulerAnglesXYZ())
		LeftHand.CFrame = (camCF*CFrame.new(cfLH.p*HeadScale))*CFrame.fromEulerAnglesXYZ(cfLH:ToEulerAnglesXYZ())
	end
end

end)

You could give the player NetworkOwnership (on the server) of the “hands”, and use a BodyPosition and a BodyGyro (on the client) to control them.

3 Likes

are you able yo give me a example, like not like the code but more on how to use this network thing? I actually never heard of this before so I want to see more of a example with it if thats ok.

You’d probably tell the server to give the player network ownership of the hands when the player joins the game/when they spawn, by using the function :SetNetworkOwner(player) on your “hand” parts. After you’ve given the player network ownership, make the BodyMovers on the client to move the hands.

Since you’ve given the player network ownership over the hands, they now have control of the hands, meaning the BodyMovers effects will be shown on the server.

oh ok so, this owner stuff controls on the client but then also shows on the server? So I control the BodyMovers which then shows on the server? Am I correct?

Yes, you are correct. Let me know if you encounter any problems with this that you need help with!

1 Like

okay so question. Once I set it to the server thats it? I can just make them move with the local script or am I just doing every thing wrong lol

server script

script.Parent.OnServerEvent:Connect(function(player)
local hands = game.ReplicatedStorage.Hands:Clone()
script.MakeHands:FireServer()
hands.Parent = workspace
hands.Name = player.Name…“Hands”

-- Set the server as the owner of the projectile
hands.R.PrimaryPart:SetNetworkOwner(nil)
hands.L.PrimaryPart:SetNetworkOwner(nil)

end)

1 Like

I’m pretty sure you set the NetworkOwner to be the client. If you set the owner to be the server then the hand would be controlled by the server and not the client (I don’t have much experience with NetworkOwnership)

IF that is your serverscript it has :FireServer() in it witch does not work on servers only clients so that would be your error and you wouldent set the hands primary part’s network owner you would set the entire hand model to the player and you wouldent set it to nil lol@@@@@@

1 Like

Make the MakeHands remote function into a bindable event so the server can call it

1 Like

VR_Test.rbxl (34.4 KB)

This right here is a test game with some rough but pretty not bad code that you could use
This contains
Smooth Turning
Serversided VR (Align Positions/Orientations)
Camera placed in the right spot
Multiplayer blah blah blah you get my point

Still working on this framework that will be opensource for the public (when done)
(Force R6 to make it work)

Set the network owner to the player object, like so:

hands.R.PrimaryPart:SetNetworkOwner(player)
hands.L.PrimaryPart:SetNetworkOwner(player)