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

CFrame script not functioning, no errors?

Asked by 9 years ago

So I'm trying to make a model with a primary part slide up and down on every click (Up on click one, Down on click two), but when I click it. Bam, nothing! Nor no errors.

01function click()
02if(script.Parent.Status.Value)=="Closed" then
03script.Parent.Status.Value="Opening"
04movements=0.2
05speed=0.2
06for i=1,movements do
07wait(0.01)
08script.Parent.PLT:SetPrimaryPartCFrame(script.Parent.PLT.PrimaryPart.CFrame + Vector3.new(0,speed,0))
09end
10script.Parent.Status.Value="Open"
11 
12elseif(script.Parent.Status.Value)=="Open" then
13script.Parent.Status.Value="Closing"
14movements=0.2
15speed=0.2
View all 23 lines...
0
Put some prints in your code, it'll tell you where you went wrong. TheDeadlyPanther 2460 — 9y

1 answer

Log in to vote
2
Answered by
DevSean 270 Moderation Voter
9 years ago
01local status = script.Parent.Status
02local plt = script.Parent.PLT
03local speed = 0.2
04local movements = 2
05 
06function click()
07    if (status.Value == "Closed") then
08        status.Value = "Opening"
09        for i=1, movements do
10            wait(0.01)
11            plt:SetPrimaryPartCFrame(plt.PrimaryPart.CFrame + Vector3.new(0,speed,0))
12        end
13        status.Value="Open"
14    else
15        status.Value="Closing"
View all 24 lines...
1for i=1, 0.2 do -- (0.2 from your movements variable)

Has no effect as the default step is 1.

Instead you should use:

1for i=1, 2 do

To loop twice.

I've also tidied up the script a bit.

0
Note, when answering, try to include a description of what you did to make it work. TheHospitalDev 1134 — 9y
0
I was going to leave some comments but I needed to go to sleep, I've edited the answer for you. DevSean 270 — 9y
Ad

Answer this question