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

How do i make my no clip script activate and deactivate when you press n?

here is the script

	Stepped = game:GetService("RunService").Stepped:Connect(function()
		if not Clipon == false then
			for a, b in pairs(Workspace:GetChildren()) do
				if b.Name == Plr.Name then
					for i, v in pairs(Workspace[Plr.Name]:GetChildren()) do
						if v:IsA("BasePart") then
							v.CanCollide = false
						end end end end
		else
			Stepped:Disconnect()
		end
	end)

2 comments

0

Are you meaning inside of the script or the script itself?

0

It would be better if you could just put this code in a function and then call that function via UserInputService. You can read more about it here: https://www.youtube.com/watch?v=4z1HVwe0sLE

1 answer

I'm feeling generous. Go crazy, kid:

####! Not R15 compatible !

--###----------[[SERVICES]]----------###--
local UserInputService = game:GetService("UserInputService")

local RunService = game:GetService("RunService")


local Players = game:GetService("Players")



--###----------[[VARIABLES]]----------###--
local Player = Players.LocalPlayer


local ClipToggleKey = Enum.KeyCode.N

local ClipEnabled = true

local UnClipConnection;



--###----------[[FUNCTIONS]]----------###--
local function HandleClip(InputObject, GameProcessedInput)
	if (GameProcessedInput) then return end
	---------------
	if (InputObject.KeyCode == ClipToggleKey) then
		---------------
		ClipEnabled = (not ClipEnabled)
		---------------
		if (not ClipEnabled) then
			---------------
			local Character = Player.Character or Player.CharacterAdded:Wait()
			---------------
			UnClipConnection = RunService.Stepped:Connect(function()
				---------------
				Character.Head.CanCollide = false
				Character.Torso.CanCollide = false
			end)
			---------------
		else
			UnClipConnection:Disconnect()
		end
	end
end



--###----------[[SETUP]]----------###--
UserInputService.InputBegan:Connect(HandleClip)

#####RESOURCES:

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