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

How do I properly enable and disable player input?

Asked by 5 years ago
Edited 5 years ago

I am trying to disable and enable player's input so that they cannot move/jump. I am aware of setting JumpPower and WalkSpeed to 0, but the player is being moved via scripts. Player touches npc, triggers cut scene and disables controls.

RunService:UnbindFromRenderStep("ControlScriptRenderstep")

Player then battles npc and either wins or dies.

If it wins it will run the code,

RunService:BindToRenderStep("ControlScriptRenderstep", Enum.RenderPriority.Input.Value, function(dt) Controls:OnRenderStepped(dt) end)

and then the player can move again. However, when it dies it will run the same code, however the player cannot move. I have tried running an event right when the player's health is set to 0, I've tried

    game.Players.PlayerAdded:Connect(function(player)

player.CharacterAdded:Connect(function(character)

character:WaitForChild("Humanoid").Died:Connect(function()

repeat wait() until player.Character

game.ReplicatedStorage.Remotes.CharDiedRemote:FireClient(player)

print("Died")

end)

end)

end)

and then in a local script

    local function CharDied()

print("Respawned")

RunService:BindToRenderStep("ControlScriptRenderstep", Enum.RenderPriority.Input.Value, function(dt) Controls:OnRenderStepped(dt) end)

end

game.ReplicatedStorage.Remotes.CharDiedRemote.OnClientEvent:Connect(CharDied)

It prints both died and respawned, but still doesn't allow player to move.

Is there a better way of doing this, or am I doing something incorrectly?

1 answer

Log in to vote
1
Answered by
Fifkee 2017 Community Moderator Moderation Voter
5 years ago
  1. Find the PlayerScripts inside of the Player Object
  2. Find the PlayerModuleScript
  3. Find the ControlModule Script, then require it.
  4. Now, you should have something like this: local Variable = require(game.Players.LocalPlayer.PlayerScripts.PlayerModule.ControlModule)
  5. Call disable on the control module variable.
  6. When the time is right, you can call :Enable() on the required control module variable.
0
I've actually tried this as well, with the same result. It will enable controls if win, but not if the player dies. WizyTheNinja 834 — 5y
1
I got it to work, I added in repeat wait() until player.Character:FindFirstChild("Head") before firing the remote, and it worked. Must have been trying to activate while they didn't exist or something. WizyTheNinja 834 — 5y
0
WaitForChild is your best friend lol Fifkee 2017 — 5y
Ad

Answer this question