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