Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Movement disabled when I respawn?

I've been trying to create a camera system in which I want the player to be unable to move while they are accessing the cameras. For some reason, it only works until you die and death disables the players movement until you access the cameras again for some reason which I don't understand. Can someone help? I've tried to create several failsafe's but they all don't work.

Here is the main pieces code - I removed some unimportant stuff which I know doesn't interfere with it:

local Plr = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local FindPlayerGUI = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local UIS = game:GetService("UserInputService")
local controls = require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()
_G.OpenedCams = false -- Global in case I need to use it in different script



-- Enable and Disable cams.
UIS.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.C then
		if _G.OpenedCams == false then
			_G.OpenedCams = true
			print("Enter Cams")
			FindPlayerGUI.CamsGUI.Enabled = true 
			Camera.CameraType = Enum.CameraType.Scriptable
			Camera.CFrame = workspace.DefaultCams:FindFirstChild("Cam"..script.Parent.CamID.Value).CameraPart.CFrame
			controls:Disable()
			
		elseif _G.OpenedCams == true then
			_G.OpenedCams = false
			print("Exit Cams")
			FindPlayerGUI.CamsGUI.Enabled = false
			Camera.CameraType = Enum.CameraType.Custom
			Camera.CameraSubject = Plr.Character.Humanoid
			controls:Enable()
		end
	end
end)

1 answer

I found another way of freezing movement which fixed the issue

You will need these two variables

local ContextActionService = game:GetService("ContextActionService")
local FREEZE_ACTION = "freezeMovement"

I used this to disable movement

ContextActionService:BindAction(
	FREEZE_ACTION,
	function()
		return Enum.ContextActionResult.Sink
	end,
	false,
	unpack(Enum.PlayerActions:GetEnumItems())
)

And this to re-enable movement

ContextActionService:UnbindAction(FREEZE_ACTION)

This discussion is preserved as it was. New answers, comments, and votes are closed.