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

Why won't this script make all the parts in the model not have collisions?

game.Players.LocalPlayer.Backpack:WaitForChild("Staff Card").Changed:Connect(function(newVal)
    for i,child in pairs(game.Workspace.Staffdoors:GetChildren()) do
        if child:IsA("Part") then
            if newVal == true then
                child.CanCollide = false
            else
                child.CanCollide = true
            end
        end
    end
end)        

Please help, I have no Idea why it is doing this. I want to make all the parts in the group, "Staffdoors" to not have collisions when a player possesses a certain tool. Please help!

6 comments

0

Someone please this is crucial to the development of my game

0

newVal returns the property that was changed/edited. :| Say you changed a part's Anchored property, the function will return Anchored.

0

So what do I do

0

Simply remove lines 4, 6, and 8.

0

Doesn't work

0

Try replacing line 4 with "if child.CanCollide == true then"

1 answer

✓ Accepted answer

if newVal == true then is a nice attempt but does not change ANYTHING at all since the function is fired when Backpack:WaitForChild("Staff Card") is changed

try this script since if newVal == true then does nothing

game.Players.LocalPlayer.Backpack:WaitForChild("StaffCard")
.Changed:Connect(function(newVal)
    for i,child in pairs(game.Workspace.Staffdoors:GetChildren()) do
        if child:IsA("Part") then
                child.CanCollide = false
        end
    end
end)        

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