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?
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)