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

Why wont this SetPrimaryPartCFrame() script work?

Asked by 8 years ago
local Sensor1 = script.Parent.S1
local doorl1 = script.Parent.L1
function onTouched(hit)
    for i = 20,0,0.01 do
        doorl1:SetPrimaryPartCFrame(CFrame.new(i, 0, 0))
        wait()
    end
end
Sensor1.Touched:connect(onTouched)

Why doesnt this work? Help please :(

0
Are you sure you have a PrimaryPart set to the model? ScriptGuider 5640 — 8y
0
Yes. PlanetDevv 5 — 8y
0
Try -0.01 instead of 0.01, because if you add 0.01 to 20, it will never reach 20. TheHospitalDev 1134 — 8y

1 answer

Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
8 years ago

Your for loop is inversed, wich means you have to do

for i = 20,0,-0.01 do -- Inversed the 0.01 to -0.01 because you have 20,0 instead of 0,20
     doorl1:SetPrimaryPartCFrame(CFrame.new(i, 0, 0))
     wait()
end

Ad

Answer this question