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

Why is it not disabling the controls?

Asked by 3 years ago
Edited 3 years ago

So I'm a very new Scripter, and I'm trying to make the players controls disable when they touch (Pass Through) a block. CanTouch is enabled, CanCollide isn't, I've looked on DevForum and here and every on post that wants to know how to disable controls is always given something like this Script:

1| local gate = script.Parent -- The Block

2| local controls = require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()

3|

4| gate.Touched:Connect(function()

5| controls:Disable()

6| end)

So I put that Script in, and it isn't working. In the Output all it says is " attempt to index nil with 'PlayerScripts' ".

Can anyone give me a script that should work or a way to fix this please?

1 answer

Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
3 years ago

Try this

Put this server script inside the gate

make a remote event in ReplicatedStorage called DisableControls

local disableControlsRE = game:GetService("ReplicatedStorage"):FindFirstChild("DisableControls")

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then

        disableControlsRE:FireAllClients()

    end
end)

Local script, Put this in StarterGui

local disableControlsRE = game:GetService("ReplicatedStorage"):FindFirstChild("DisableControls")

disableControlsRE.OnClientEvent:Connect(function()

    local PlayerModule = require(game:GetService("Players").LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule"))

    local controls = PlayerModule:GetControls()

    controls:Disable()

end)
Ad

Answer this question