Ad
Log in to vote
1

Please help my Walkthrough Players script is not working?

Asked by 8 days ago

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

Log in to vote
0
Answered by 8 days ago

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.

0
Well, my laptop is really laggy when i do player testing. It just opens loads of studios. poppyloverb 19 — 8d
Ad
Log in to vote
0
Answered by
Vong25 121
8 days ago
Edited 3 days ago

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

0
It is allready in StarterPlayerScripts poppyloverb 19 — 8d

Answer this question