How to disable player control in server script?

I’ve been trying recently to make the player unable to move.
I found some posts on the Dev Forum about this, however they were in a local script:

They’re supposed to be about a server script, but they didn’t work for me.

I don’t know, maybe you can find something in my script?

my script?
-- create a variable called debounce that is set to nil
local debounce = nil
local SmileParts = (game.Workspace.KillParts:GetChildren())



-- when something touches the script parent
script.Parent.Touched:Connect(function(touchedPart)
	if debounce == true then return end

	local character = touchedPart.Parent
	local player = game:GetService('Players'):GetPlayerFromCharacter(character)
	
	
	
	if player == nil then return end
	debounce = true

	-- Play the sound
	game.Workspace.Sounds.Sound:Play()
	
	--------------------------
	--Here I tried to put it--
	--------------------------
	
	
	for i, child in ipairs(game.Workspace.KillParts:GetChildren()) do
		child.Material = Enum.Material.SmoothPlastic
	end

	-- wait 3 seconds
	task.wait(3)

	-- move the character to Spawn1
	character:PivotTo(game.Workspace.Spawn1.CFrame)
	
	wait(0.2)
	
	game.Workspace.Sounds.Sound2:Play()
	for i, child in ipairs(game.Workspace.KillParts:GetChildren()) do
		child.Material = Enum.Material.Neon
	end


	debounce = nil
end)

I’ve tried everything. Maybe you can infer LocalPlayer from character.
I want to avoid RemoteControls as much as possible because I consider it unnecessary and it only annoys me.

Unable to move like walking and jumping?

If you are trying to make a Touched Event. You should always change Humanoid properties on the server. You can use Remote Events for this.
Local Script:

local RS = game:GetService("ReplicatedStorage")
local Event = RS:WaitForChild("RemoteEvent")

local part = workspace.Testpart

part.Touched:Connect(function(hit)
	local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if plr then
		Event:FireServer(plr)
	end
end)



ServerScript: 
local RS = game:GetService("ReplicatedStorage")
local Event = RS:WaitForChild("RemoteEvent")

Event.OnServerEvent:Connect(function(plr)
	local Character = plr.Character or plr.CharacterAdded:Wait()
	local Humanoid = Character:WaitForChild("Humanoid")
	if Humanoid then
		print("works")
		Humanoid.WalkSpeed = 0
		Humanoid.JumpHeight = 0
	end
end)
1 Like

This is a simple method to prevent a player from moving

function freeze(plr: string | Player | Model, value: boolean)
	local character = typeof(plr) == "string" and game:GetService("Players")[plr].Character or plr.ClassName == "Player" and plr.Character or plr.ClassName == "Model" and plr
	for _, CharacterPart in pairs(character:GetChildren()) do
		if CharacterPart:IsA("BasePart") then
			CharacterPart.Anchored = value
		end
	end
end

True but i’d rather set walk speed and jump power to 0 so that the animation still plays and the player doesn’t end up floating in the air