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:
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!
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.
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
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)
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
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
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.