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

Why won't this script work, even though everything is right?

Asked by 6 years ago

I checked all the syntax and there aren't any errors that I can see. Can you guys find something?

if game.Players.LocalPlayer.Backpack.Staffcard == true then
    for i,child in pairs(game.Workspace.Workdoors:GetChildren()) do
        if child:IsA("Part") then
            child.CanCollide = false
        else
            child.CanCollide = true
        end
    end
end
0
What about this script isn't working? theCJarmy7 1293 — 6y
0
Collisions aren't turning off MustangHeart 67 — 6y
0
Please help MustangHeart 67 — 6y

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

If Staffcard is a value inside the Backpack, you have to check if Staffcard.Value == true instead of just Staffcard == true (the instance itself will always be treated as being true). Also, if you wanted this to happen whenever the Staffcard value changed, you would have to put it in a Changed function. Also I'm not sure why you're tying to change the CanCollide of something if it isn't a part.

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

Otherwise, if it is a tool, you may want to look into using FindFirstChild or ChildAdded.

0
I'm trying to make all the parts in a model have no collisions.This doesn't work for some reason MustangHeart 67 — 6y
Ad

Answer this question