Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

ContextActionService Freezes all Player controls in the server?

Asked by 4 years ago

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

0
Why not just set their walkspeed to 0? iOwn_You 543 — 4y
0
Or anchor their HumanoidRootPart iOwn_You 543 — 4y
0
Because if I set their walkspeed to 0 the whole Humanoid:MoveTo(DestinationPoint) would also stop RazzyPlayz 497 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

0
This is all done on a LocalScript because the function ContextActionService:BindAction can only be called by local scripts RazzyPlayz 497 — 4y
0
I edited my post. I understand what's wrong. LightningLIon58 49 — 4y
Ad

Answer this question