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

Help with a translating model?

Asked by 7 years ago

I want a gate (Model) that slides into one position on click and slides back into its original position on second click. almost everything works well except for when i change the ".01" to anything different, it doesn't open nor close anymore.

script.Parent.ClickDetector.MouseClick:connect(function()
    local state = script.Parent.Parent.State
    if state.Value == false then
        state.Value = true
        local Gate = script.Parent.Parent.Gate
        for i = 0, .7, .01 do
            Gate:SetPrimaryPartCFrame(Gate:GetPrimaryPartCFrame() * CFrame.new(0,0,-i))
        end
    else
        state.Value = false
        local Gate = script.Parent.Parent.Gate
        for i = 0, .7, .01 do
            Gate:SetPrimaryPartCFrame(Gate:GetPrimaryPartCFrame() * CFrame.new(0,0,i))
        end
    end         
end)
0
Would you mind telling us what you are changing it to? lukeb50 631 — 7y
0
I'm changing it to "1" creeperhunter76 554 — 7y

1 answer

Log in to vote
0
Answered by
lukeb50 631 Moderation Voter
7 years ago
Edited 7 years ago

Based on you telling me you are changing it to 1, here is the problem

your for loop takes 3 arguments: i, the ending number and the increment (These are not their exact names, just what they are)

your code that you posted goes up by .01 up to .7 every time, starting at 0. This works because both i and the increment are smaller than the end.

when you change it to 1, it won't work well because your asking it to go from 0 to 1 on the first round. since 1>0.7, the loop has executed the amount of times you asked it to and will end.

0
thanks, i'm not very good with the "for" syntax creeperhunter76 554 — 7y
Ad

Answer this question