Lock Movement and Camera Position For multiple People at once?

Hey all, I’m trying to setup a system where it teleports 2 or more people to a location, locks their movement, then sets their camera to a specific part. I got the teleportation down but the other two are giving me quite the challenge. As for movement I’ve tried just setting the walkspeed to 0 but for whatever reason that won’t work. And as for the camera I tried using CameraSubject but it only for camera for 1 of the 2 players and even then they could still look around (I want it to be static with no inputs moving it). Here are the scripts I tried, any tips or solutions would be greatly appreciated!

Movement Disable Attempt:

local function disablePlayerMovement(player)
	if player and player.Character then
		local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
		if humanoid then
			humanoid.WalkSpeed = 0
			humanoid.JumpPower = 0
		end
	end
end

local function restorePlayerMovement(player)
	if player and player.Character then
		local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
		if humanoid then
			humanoid.WalkSpeed = 16
			humanoid.JumpPower = 50
		end
	end
end

Camera Set Attempt:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local duelCameraEvent = ReplicatedStorage:WaitForChild("DuelCameraEvent")

local cameraPart = script.Parent
local playersInDuel = {}

local function lockCamera(player)
	local camera = workspace.CurrentCamera
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CameraSubject = cameraPart
end

local function unlockCamera(player)
	local camera = workspace.CurrentCamera
	camera.CameraType = Enum.CameraType.Custom
end

duelCameraEvent.OnServerEvent:Connect(function(player, cameraTarget)
	if cameraTarget == cameraPart then
		playersInDuel[player] = true
		player:LoadCharacter()  -- ensure the player resets if needed
		duelCameraEvent:FireClient(player, cameraPart)
	else
		playersInDuel[player] = nil
		duelCameraEvent:FireClient(player, nil)
	end
end)

I think I would recommend for movement to anchor the character’s humanoid root part as that just locks the whole character to their current CFrame but animations are still playing (e.g. if the character was running then you anchor them, they will still be doing the running animation).

For setting their camera to a specific part (I am assuming that you mean set it to the part’s CFrame not looking at it), I would set the CFrame of the camera to the part’s CFrame using RunService.RenderStepped. In theory, the player won’t be able to still look around.

I hope my horrible wording of everything I just explained made any sense and helped you. If it didn’t, then I got no other ideas on how you would go around doing this and I look a bit stupid.

1 Like

add a print at humanoid.WalkSpeed to make sure it’s going through and make sure there isn’t any other code changing the walkspeed by doing ctrl + shift + f and then searching for WalkSpeed = and for jumping i recommend you use humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)

1 Like

Thanks for the help! The Camera stuff worked great, for the movement disable I just had to make it so it would wait until they stand still after teleporting.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.