I found a way to disable the player's movement, but I don't know how to use it

I recently found this topic while searching for how to disable to player’s movement, but I don’t really get it. (I can’t post on the original topic because it’s locked)

When I put this on a script, I get an error

local controls = require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()
controls:Disable()

Error:
image

I’m also not completely sure, would this freeze the player, or would this just disable their movement? I’m trying to force them to walk using :MoveTo()

I’m using a server script that triggers when the player touches a brick.

Could someone please explain how it works and what to do? Thanks!

2 Likes

The script looks like it’ll just temporary disable the movement, I think it also depends on where you wanna put the code

Maybe try putting it in StarterPlayerScripts?

1 Like

I want it to be a server script, would that still work?

I’m trying to make it so that when the player touches something, it forces them to walk somewhere, and I want them to be unable to move when they are being forced.

No this will only make it so that the player cannot use controls to move(WASD, or whatever they use to move their character). This does not mean that you cannot move the character via scripts or local scripts.

Yes, I want to so that they cannot break the forced move connection, but when I use the lines

local controls = require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()
controls:Disable()

it gives an error.

This attempts to control player input, so no. Also it uses LocalPlayer, which can only be used on the client.

I don’t believe you’re able to use that on the server, as configuring with the Player’s Control Scripts mainly work around ContextActionService

But I think you could use RemoteEvents in order to make that work by calling FireClient() on the server, and OnClientEvent() on the client, but I’m not entirely certain

That is because you can only do it client side.

If you want to stop the character from moving just anchor their HumanoidRootPart and unanchor it when you want them to move again.

1 Like

Would anchoring the HumanoidRootPart make the player still able to move if using :MoveTo()?

Yes, MoveTo() is basically just SetPrimaryPartCFrame() but takes account to collisions.

1 Like

Mine is freezing the player…
Here’s my code if you need it:
Brick 1:

local endpos = game.Workspace.Teleports.End
local db = {}

function TpFunc(hit)
	local char = hit.Parent
	if game.Players:GetPlayerFromCharacter(hit.Parent) and not db[char.Name] then
		hit.Parent.HumanoidRootPart.Anchored = true
		db[char.Name] = true
		--local controls = require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()
		--controls:Disable()
		char.Humanoid:MoveTo(endpos.Position)
		wait(4)
		db[char.Name] = false
	end
end 
script.Parent.Touched:connect(TpFunc)

Brick 2:

local db = {}
local tp = "TpTo1"
function TpFunc(hit)
	local char = hit.Parent
	local Pos = game.Workspace.TpTo:FindFirstChild(tp)
	if Pos and game.Players:GetPlayerFromCharacter(hit.Parent) and not db[char.Name] then 
		hit.Parent.HumanoidRootPart.Anchored = false
		game.ReplicatedStorage.CircleEnable:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
		wait(1.5)
		db[char.Name] = true
		hit.Parent:moveTo(Pos.Position) 
		--	wait(2)
		--char.Humanoid.PlatformStand = false
		wait(4)
		db[char.Name] = false
		
	end 
end 
script.Parent.Touched:connect(TpFunc)

To clarify, I’m using Humanoid:MoveTo().

You didn’t unanchor the HumanoidRootPart so that’s why it’s still frozen.

I anchor it when the player touches brick 1, and unanchor it when the player touches brick 2, because I want them to walk there.

Am I doing something wrong?

Just a reminder, but you should also create a Player variable so that it’s easy to keep track of

Anchoring the HumanoidRootPart I believe would just result in the player being frozen, with no way to move whatsoever

tenor (5)
Also you aren’t inserting anything inside your debounce table, any reason why?

local endpos = game.Workspace.Teleports.End
local db = {}
local DisableMovementEvent = game.ReplicatedStorage:WaitForChild("DisableMovement")

function TpFunc(hit)
	local char = hit.Parent
    local player = game.Players:GetPlayerFromCharacter(char)
	if player and not table.find(db, char.Name) then
		table.insert(db, 1, char.Name)
		DisableMovementEvent:FireClient(player)
		char.Humanoid:MoveTo(endpos.Position)
		wait(4)
		for Number, PlayerName in ipairs(db) do
            if PlayerName == char.Name then
               table.remove(Number, PlayerName)
            end
        end)
	end
end 

script.Parent.Touched:connect(TpFunc)
--Client
local DisableMovementEvent = game.ReplicatedStorage:WaitForChild("DisableMovement")
local Player = game.Players.LocalPlayer
local Controller = require(Player:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule")):GetControls()

DisableMovementEvent.OnClientEvent:Connect(function()
    Controller:Disable()
end)

I have no clue if this would work but I guess you can try it

Just asking, would my debounce still work?

I’d assume so, I did go ahead and change some things relevant to your debounce code after all :thinking:

You can’t put it in a Server Script, it would work perfectly fine on a local script. If you really want to use a server script, just send a remote event. I’ve tried something similar with :MoveTo, but I don’t know how to do it exclusively for the server.