How do I make a Noclip Script

First of all, I want to say. I am NOT doing anything bad with this. Basically in my game, we have secret agents. They can go invisible. There is keycard doors, so if you are invisible you have to pull out your card, and open the door. Thing is, people would see that. So I want to make a noclip script for them to use so they can walk through the doors.

How would I do this?

I have know how to do the keybind for it, and how to import it into my script. I just don’t know what properties the script should change of the player, ect.

Thanks for your help,
Alex. :slightly_smiling_face:

2 Likes

CanCollide property is your best friend. Here is how i would do it.

for i, v in pairs(game.Workspace:GetDescendants()) do
    is v:IsA("Part") or v:IsA("Meshpart") then -- add more depending on types of blocks.
        v.CanCollide = false
    end
end

Doesn’t work for me. Let me check for errors.

Ok, so it works… but I fall out of the world. Haha.

You can use Collision Filtering to make separate collision groups for the doors and the secret agents so that only they pass through.

You’ll need to loop through each part in the player character and set their collision groups individually, though.

2 Likes

If collision groups or can collide is a problem for you, an alternative is to simply make the tools invisible.

Is there a way I can use that to make it so my floors’ CanCollide option is always set to true? Even if it’s changed in a script?

Use the changed event (an event in basically every roblox instance) to check for when a property has been changed, if can collide has been changed to false just set it back to true.

I would recommend making a table of all the secret agents, then firing a remote event to each of them as so. I would also recommend making a folder of all the doors in the local script, so it’ll be easier to make them noncollidable (and maybe even half transparent)


Server Script:

local remote = --Remote Event here
local agents = {} --agents table (you've probably already set up a system that choses agents)

for _, p in pairs(agents) do
    remote:FireClient(p)
end

Local Script

local remote = --remote event here

remote.OnClientEvent:Connect(function()
    local doors = workspace.Doors --get this variable properly

    for _, d in pairs(doors:GetChildren()) do
        if d:IsA("BasePart") then
            d.CanCollide = false
            d.Transparency = 0.5
        end
    end
end)

Then at the end of the round, you can fire a remote event to all clients that sets the doors back to collidable and nontransparent:

Server Script:

local remote = --remote event here

remote:FireAllClients()

Local Script:

local remote = --remote event here

remote.OnClientEvent:Connect(function()
    local doors = workspace.Doors --get this variable properly

    for _, d in pairs(doors:GetChildren()) do
        if d:IsA("BasePart") then
            d.CanCollide = true
            d.Transparency = 0
        end
    end
end)

How do I make a part a basepart?

The term “BasePart” applies to Parts, Wedges, Cylinders, Spheres, CornerWedges, MeshParts, and Unions

So could I just put all the Floors in my game in a folder called “Floors” and then do:


for i, v in pairs(game.Workspace:GetDescendants()) do
    if v:IsA("Part") or v:IsA("Meshpart") then 
        v.CanCollide = false
    end
end
for i, v in pairs(game.Workspace.Floors:GetDescendants()) do
    if v:IsA("Part") then
        v.CanCollide = true
    end
end

So then right after it turns off CanCollide, it turns it back on but only for the floors?

1 Like

Yep, that’s right. (30 characters)

Or, here’s a brighter idea, put your doors in a folder called Doors and only change their properties. Don’t mess with the floors, walls and other furniture’s Properties.

If you want the agents to walk through walls, doors and all, you could use this solution:

local noclip = false
game:GetService("RunService").RenderStepped:Connect(function()
   if noclip then
    game.Players.LocalPlayer.Character.Humanoid:SetState(11)
   end
end

And just change the noclip variable.
If you want the players to only noclip through doors, you could make a folder inside workspace called “Doors” and do this:

for i,v in pairs(workspace.Doors:GetDescendants()) do
if v:IsA("BasePart") then
v.CanCollide = false
end
end

I personally recommend the second solution, though you won’t fall through the floor with the first solution.


Also, @dibblydubblydoo, you don’t have to class check for every single type of part, you can just use v:IsA("BasePart") instead, because all Part classes, like Unions, Meshes, and Wedges, all inherit from the class BasePart.

1 Like

I think making the players parts cancollide on is better, instead of having to loop thorugh the whole game. Also to make the player not fall, you could weld two bricks to their legs, and make those bricks cancollide true

Yeah that’s what I was originally going for.

But if you weld Parts to their legs and make them CanCollide True you are going to collide with the doors…

2 Likes

just create a condition
for i, v in pairs(game.Workspace:GetDescendants()) do
if v:IsA(“Part”) or v:IsA(“Meshpart”) and v.Name ~= (your floor’s name) then
v.CanCollide = false
end
end