Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Won't Make All Players CanCollide False?

Asked by 8 years ago
Edited 8 years ago

I created a local script inside of Starter Pack to make all players CanCollide false. When I test with 2 people with the test option in studio, it works the first second then stops. I get no error. Here is the code:

local player = game.Players.LocalPlayer
local character = player.Character
wait(.1)
game:GetService('RunService').Stepped:connect(function()
local parts = character:GetChildren()
if parts.ClassName == "Part" and parts.ClassName == "Hat" then
    parts.CanCollide = false

end
end)
1
Is FE turned on? BinaryResolved 215 — 8y
0
No it is not, but doing so would break the whole game CheekySquid 78 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

You're using tabled wrong.

The GetChildren() method returns a table of everything inside of whatever you called the function for.

ScriptGuider explains tables very well. Here's a link to his answer.

Your question,

For your question, we don't even need to use tables really. Besides looping through one. We're going to use a Pairs Loop. A pairs loop will let us loop through everything inside of a table and give us the value in the table each loop.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
wait(.1)
game:GetService('RunService').Stepped:connect(function()
    local parts = character:GetChildren()
    for i,v in pairs(parts) do
        if v:IsA("Part") then
            v.CanCollide = false
        end
    end
end)

I also waited for the character to load, and checked if what was inside the character was a part.

I'm not sure this is going to make the character a ghost, but this is a fix to your problem.

Good Luck!

Ad

Answer this question