Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Disabling Characters Controls Breaking?

local MasterControl = require(game.Players.LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("ControlScript"):WaitForChild("MasterControl"))

MasterControl:Disable()
wait(3)
MasterControl:Enable()

This is inside a local script that is inside a part. When touched the part clones this script into the playergui and disables it. After 4 seconds (yes ik it says 3 but I need it to enable) the script destroys. Now this completely breaks the system, it makes your character walk backward while you can't control it.

1 answer

✓ Accepted answer

dude, rather than putting it inside the local script inside the individual part, do it inside

StarterPlayer > StarterPlayerScripts

and here's the code with some brief explanation

local Player = script.Parent.Parent --// Get the player as a variable
local Character = Player.Character
if not Character ~= nil then
	Character = Player.CharacterAdded:Wait() --// Wait for the character if the character doesn't exist yet
end
local Humanoid = Character:WaitForChild("Humanoid") 

local MasterControl = require(script.Parent:WaitForChild("ControlScript"):WaitForChild("MasterControl"))

local BodyParts = { --// The table of the character bodyparts that can activate the code
	"Right Leg";
	"Left Leg"
}

local ImmobilizeDuration = 3 --// The duration of the immobilization

local Immobilizer = function()
	for _, Part in next, BodyParts do --// Get all the names of the parts required to touch
		Character[Part].Touched:Connect(function(Touched) --// "Character[Part]" is when the script goes to the Character, 
			--// and inside the square brackets, the script will find the bodyparts the table has listed
			if Touched.Name == "disabler" and Humanoid:GetState() ~= Enum.HumanoidStateType.Dead then --// The legs touches a certain part
				--// AND checks if the character is not dead
				MasterControl:Disable()
				wait(ImmobilizeDuration)
				MasterControl:Enable()
			end
		end)
	end
end

Humanoid.Died:Connect(function() --// If you want to run this function again, better to add this
	--// Or else it won't work for the new character after death
	Character = Player.CharacterAdded:Wait() --// Waits for the new character to respawn
	Humanoid = Character:WaitForChild("Humanoid")
	Immobilizer() --// After waiting, run this code
end)

Immobilizer() --// For the first time without dying, this code will run

as you may notice, there has been some changes

This discussion is preserved as it was. New answers, comments, and votes are closed.