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

Why would this script not work? It works with other things.

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
cd = script.Parent.ClickDetector

cd.MouseClick:connect(function()
    a = game.Workspace:GetChildren(Boat)
        for i,v in pairs(a) do
            if v.Name == "Part" then 
                for i = 1, 1000 do
                    v.CFrame = v.CFrame * CFrame.new(0,.5,-.2)
                        wait(.01)
                    v.CFrame = v.CFrame * CFrame.new(0,-.5,-.2)
                wait(.01)
                end
            end
    end
end)

The script, OnClick, is supposed to make everything in/on the boat move to the left, and slightly move up and down. I've also tried this:

cd.MouseClick:connect(function()
    game.Workspace.Boat:GetChildren()
        for i,v in pairs() do
            for i = 1, 1000 do
                v.CFrame = v.CFrame * CFrame.new(0,0,-.2)
            wait(.01)
        end
    end
end)

To the moderator note-- I will make sure to do that next time.

1 answer

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

Well, looking at the script, everything isn't going to move in unison. In your 2nd for loop, you have two waits in there. That would delay the next part from moving by .02 seconds, and so forth. In other terms, it would basically look like a snake moving. If you want it to move in unison, I recommend creating another for loop with a wait between each for loop so it moves everything together. One other thing I noticed is, in your first for loop, you put Boat. If you're trying to move the boat, you should put game.Workspace.Boat:GetChildren(). I would've put this all as a comment, but it didn't fit. Hope these tips help you.

cd.MouseClick:connect(function()
    game.Workspace.Boat:GetChildren()
        for i,v in pairs() do
            for i = 1, 1000 do
                v.CFrame = v.CFrame * CFrame.new(0,0,-.2)
        end
    -- the wait would go here if you were to add something else. The above is moving everything in unison as you wanted.
    end
end)

0
Oooh, thanks. Lightdrago 95 — 9y
0
No problem. Test this out. If it does happen to work for you, feel free to bump up my reputation and accept this answer! Shawnyg 4330 — 9y
0
So, delete the variable 'a' and in your for loop, put what I put in my answer. Shawnyg 4330 — 9y
0
I edited the second thing on the original post. I decided just to have it move foward, because that would be a lot simpler. Would it look like that? Lightdrago 95 — 9y
0
Not exactly, check my updated post. Shawnyg 4330 — 9y
Ad

Answer this question