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

Did I write this correctly? Doesn't seem to work for some reason.

Ok so basically I was searching through YT on "How to Make a Anti-Player Collision Script on RBX Studio" and typed out the suggested script

Script:

local Players = game:GetService("Players")
local Players = game:GetService("PhysicsService")
local GroupName = "Players"

PhysicsService:CreateCollisionGroup(GroupName)
PhysicsService:CollisionGroupSetCollidable(GroupName,GroupName,false)

Players.PlayerAdded:connect(function(Player)
	Player.CharacterAdded:connect(function(Character)
		
		local function ChangeGroup (Part)
			if Part:IsA "BasePart" then
				PhysicsService:SetPartCollisionGroup(Part,"Players")
				
			end
		end
		
		Character.ChildAdded:Connect(ChangeGroup)
		for _, Object in pairs (Character:GetChildren()) do
			ChangeGroup (Object)
		end
	end)
	end)

Is the script rigged or did I mistake?

7 comments

0

remove space between ChangeGroup (Part)

0

and why would u have 2 end) at the same line? remove the last end)'s indent

0

Are there any errors in the output? You can determine what's wrong with your script through the output, which can be seen by going to the studio topbar, going to view, and pressing output. If nothing appears in the output, let us know. If it displays an error message, please tell us the message.

0

why did you define players twice i think u meant physics

0

You have defined 'Players' twice. Change the second variable's name to PhysicsService and your script should work as is.

0

Sorry guys, this is my first script but I can try the Output method to see if it has any errors

0

Ok I'm gonna try KadenBloxYT's script. If not then I'll edit the old one according to you guys!

1 answer

✓ Accepted answer

Use this, it's more advanced, and works better.

local charRegistry = {}

local function onCharacterAdded(char)
	local reg = {}
	
	local function registerChild(obj)
		if obj:IsA("BasePart") then
			reg[obj] = obj.Name
		end
	end
	
	for _,v in pairs(char:GetChildren()) do
		registerChild(v)
	end
	
	char.ChildAdded:connect(registerChild)
	charRegistry[char] = reg
end

local function onPlayerAdded(player)
	if player ~= game.Players.LocalPlayer then
		if player.Character then
			onCharacterAdded(player.Character)
		end
		player.CharacterAdded:connect(onCharacterAdded)
	end
end

for _,v in pairs(game.Players:GetPlayers()) do
	onPlayerAdded(v)
end

game.Players.PlayerAdded:connect(onPlayerAdded)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

local rs = game:GetService("RunService")
local removeList

local function update()
	for char,reg in pairs(charRegistry) do
		if char:IsDescendantOf(game) then
			local torso = char:FindFirstChild("Torso")
			if torso and torso.CanCollide then
				-- Rename all the parts to BREAK.
				for part in pairs(reg) do
					part.Name = "BREAK"
				end
				-- Immediately switch back, and turn off collision.
				for part,name in pairs(reg) do
					part.Name = name
					part.CanCollide = false
				end
			end
		else
			if not removeList then
				removeList = {}
			end
			removeList[char] = true
		end
	end
	if removeList then
		for char in pairs(removeList) do
			charRegistry[char] = nil
		end
		removeList = nil
	end
end

rs.RenderStepped:connect(update)

Put it in a LocalScript located at StarterPlayer > StarterPlayerScripts.

If i helped mark as solution pls

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