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

How do I disable a player's control?

Asked by
Nickelz 37
5 years ago

I am trying to make a cutscene that includes a player walking to a point and such, but I cannot do that if the player decides to move by pressing the A,W,S,D keys or the arrow buttons. I used to use this:

--LocalScript
local control = script.Parent:WaitForChild("ControlScript")
function Stop()
    control.Parent = nil
end
function Resume()
    control.Parent = script.Parent
end
wait()
Stop()
wait(1000)
Resume()

but aparently that is outdated and roblox uses module scripts to control that sort of stuff now, so I looked around and I found this:

local PlayerModule = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerModule:GetControls()
Controls:Disable()

and I pasted that into a local script inside StarterPlayerScripts without any outcome. Am I doing something wrong?

0
i tested it in a blank baseplate and it worked perfectly? (player module:Disable() method) the8bitdude11 358 — 5y

1 answer

Log in to vote
1
Answered by
Kulh 125
5 years ago
Edited 5 years ago

Oops!! I did some testing, and found that the server cannot see the PlayerScripts folder!

This means you need to get the PlayerScripts folder in a local script, and fire it to the server script using a RemoteFunction!!

Here is what I came up with:

What you need:

RemoteEvent named "SendPlayerModule" located in ReplicatedStorage. Server-sided Script, located in ServerScriptService. Local-Script, located in StarterPlayerScripts.

Server script:

function playerFirstJoins(player)
    local event = game:GetService("ReplicatedStorage"):FindFirstChild("SendPlayerModule")
    local playa = player
    event:FireClient(player,playa)
end

game.Players.PlayerAdded:Connect(playerFirstJoins)

Local-Script:

local event = game:GetService("ReplicatedStorage"):FindFirstChild("SendPlayerModule")

event.OnClientEvent:Connect(function(playa)
    if playa.Name == game.Players.LocalPlayer.Name then
        local PlayerModule = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
        local Controls = PlayerModule:GetControls()
        Controls:Disable()
    else
        return
    end

end)
Ad

Answer this question