For an anti-noclip script, would creating a part and welding it to the plr be a good solution? Perhaps I could detect the collision of collidable parts and make the part size (0.2,0.2,0.2) ? Or would casting a ray each frame be a better soultion?
i would just try and experiment with both of them, if I were you.
0.05 is the min part size now
To be nice on the physics engine you should probably just anchor the part and disable collisions on it.
Every frame, before you do anything else, position the part to the character’s root’s position. No additional objects, no extra rotation calculations, and just an extra line or two of code.
Raycasting, I feel, would be really hard to get working right. Instead, you could just do :GetTouchingParts()
on the part you created and give the player a red card every time a part that isn’t a descendant of a player is found in the array that the method returns.
This method is good because it automatically excludes CanCollide false parts, however it also excludes the part that is doing the check itself. To fix this, make the part have a TouchInterest, which is accomplished by binding something to its Touched event.
Looking over this solution, this may be a little less efficient then doing a raycast thing, but overall I think it’s still a good solution due to it not being very complex.
Here’s a quick example:
local previous_cframe = CFrame.new() -- giving it a value for edge-cases
part.Touched:Connect(function() end) -- create TouchInterest required for GetTouchingParts to work on a CanCollide false part
run_service.Heartbeat:Connect(function()
part.CFrame = root.CFrame -- set the part position
local touching = part:GetTouchingParts()
for index = 0, 1, #touching do
if is_not_character_descendant(touching[index]) then -- placeholder function!!!
print("No-clip detected!")
root.CFrame = previous_cframe -- return the character to the previous position
return -- stop the code so the previous_cframe isn't needlessly set
end
end
previous_cframe = root.CFrame -- set the previous_cframe
end)
Every frame is probably a bit overkill, too. It might be better to check every second or so.
I also added in previous_cframe
variable so you can teleport the character back to where it was before it clipped with something
0.05 is the minimum part size, btw. Not 0.1.
Oh, it got lowered again?
Lol
It got lowered from 0.2 to 0.05, it wasn’t ever 0.1 minimum if I remember right.
Oof, that’s quite a shame, I deleted the part on the client and it no longer works. It appears the Touched event is local or something, i’ll use raycasts.
Sorry for the necro-bump! My bad. Will leave this here as it’s relevant in any case.
That’s not the case. If you have FilteringEnabled turned on, destroying the part from the client will not affect it on the server so the Touched connection will stay in tact in the server script.