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

ContextActionService Freezes all Player controls in the server?

Hello.

I am currently making a block where if it is hit, it freezes the charater controls and makes the player move. This does work however it disables controls for every other player in the server. I have been attempting to fix this for hours but I had absolutely 0 luck.

Here is the script I am using:

--###----------[[SERVICES]]----------###--
local ContextActionService = game:GetService("ContextActionService")

local Players = game:GetService("Players")



--###----------[[VARIABLES]]----------###--
local AutoWalk = workspace.Map.Rooms.Downstairs["Room 1"].AutoWalk_Stairs

local FreezeCharacter = "DisengageControls"
local Debounce = false

local DestinationPoint = Vector3.new(-20.209, 3.29, -480.929)



--###----------[[FUNCTIONS]]----------###--
local function AutoWalkOnTouch(CharacterBodyPart)
    local Humanoid = CharacterBodyPart.Parent:FindFirstChildWhichIsA("Humanoid")
    if (Humanoid) then
        if not (Debounce) then
            Debounce = true
            ---------------
            Humanoid.JumpPower = 0
            ---------------
            ContextActionService:BindAction(
                FreezeCharacter, 
                ---------------
                function()
                    return Enum.ContextActionResult.Sink
                end,
                ---------------
                false,
                unpack(Enum.PlayerActions:GetEnumItems())
            )
            ---------------
            Humanoid:MoveTo(DestinationPoint)
            ---------------
			ContextActionService:UnbindAction(FreezeCharacter)
			Debounce = false
        end
    end
end



--###----------[[SETUP]]----------###--
AutoWalk.Touched:Connect(AutoWalkOnTouch)

If anybody could help me with this, it would be great.

Thanks

3 comments

0

Why not just set their walkspeed to 0?

0

Or anchor their HumanoidRootPart

0

Because if I set their walkspeed to 0 the whole Humanoid:MoveTo(DestinationPoint) would also stop

1 answer

Complete edit:

The problem here is that .Touched fires to everyone when every part touches it. So instead, use Players:GetPlayerFromCharater() and make sure the player is the local player. On every touch the function runs to every player.

2 comments

0

This is all done on a LocalScript because the function ContextActionService:BindAction can only be called by local scripts

0

I edited my post. I understand what's wrong.

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