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

Please help my Walkthrough Players script is not working?

A local script in Starter Player > Starter Player Scripts.

Stack Line:

Stack Begin - Studio 17:54:16.250 Script 'Players.poppyloverb.PlayerScripts.LocalScript', Line 3 - Studio - LocalScript:3 17:54:16.251 Stack End

Code:

local player = game.Players.LocalPlayer.Character

for i,v in pairs(player:GetChildren()) do
	if v:IsA("MeshPart") then
		v.CanCollide = false
	end
end

Please help me!

2 answers

✓ Accepted answer

You actually can't set characters' body parts to be CanCollide false except for limbs. You need to use collision groups.

The first thing you'll want to do is set up a collision group like this. Make sure the box for "Player" is unchecked.

Now, the thing about this is that if you do this from a LocalScript, it will not work because your player will be non-CanCollide only on their own client, but to everyone else's they'll be the default collision group. This is why you'll want to use a PlayerAdded event from a server-side script in ServerScriptService.

local PhysicsService = game:GetService("PhysicsService")

game.Players.PlayerAdded:Connect(function(player) -- Fires when the player joins
	player.CharacterAdded:Connect(function(character) -- Fires when their character is loaded
		for i,v in pairs(character:GetDescendants()) do -- Use GetDescendants() for accessory handles, etc
			if v:IsA("BasePart") then -- Not just MeshParts, we want all types of parts.
				PhysicsService:SetPartCollisionGroup(v, "Player") -- "Player" is the name of the collision group
			end
		end
	end)
end)

If you playtest, you'll notice that players will completely walk through each other. I hope this helps! Reply if you have any questions.

1 comment

0

Well, my laptop is really laggy when i do player testing. It just opens loads of studios.

The character may not have loaded when the script runs. I recommend moving the script into StarterCharacterScripts.

1 comment

0

It is allready in StarterPlayerScripts

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