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 8 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.

function click()
if(script.Parent.Status.Value)=="Closed" then
script.Parent.Status.Value="Opening"
movements=0.2
speed=0.2
for i=1,movements do
wait(0.01)
script.Parent.PLT:SetPrimaryPartCFrame(script.Parent.PLT.PrimaryPart.CFrame + Vector3.new(0,speed,0))
end
script.Parent.Status.Value="Open"

elseif(script.Parent.Status.Value)=="Open" then
script.Parent.Status.Value="Closing"
movements=0.2
speed=0.2
for i=1,movements do
wait(0.01)
script.Parent.PLT:SetPrimaryPartCFrame(script.Parent.PLT.PrimaryPart.CFrame + Vector3.new(0,-speed,0))
end
script.Parent.Status.Value="Closed"
end
end
script.Parent.PLT.ClickDetector.MouseClick:connect(click)
0
Put some prints in your code, it'll tell you where you went wrong. TheDeadlyPanther 2460 — 8y

1 answer

Log in to vote
2
Answered by
DevSean 270 Moderation Voter
8 years ago
local status = script.Parent.Status
local plt = script.Parent.PLT
local speed = 0.2
local movements = 2

function click()
    if (status.Value == "Closed") then
        status.Value = "Opening"
        for i=1, movements do
            wait(0.01)
            plt:SetPrimaryPartCFrame(plt.PrimaryPart.CFrame + Vector3.new(0,speed,0))
        end
        status.Value="Open"
    else
        status.Value="Closing"
        for i=1, movements do
            wait(0.01)
            plt:SetPrimaryPartCFrame(plt.PrimaryPart.CFrame + Vector3.new(0,-speed,0))
        end
        script.Parent.Status.Value="Closed"
    end
end

plt.ClickDetector.MouseClick:connect(click)
for i=1, 0.2 do -- (0.2 from your movements variable)

Has no effect as the default step is 1.

Instead you should use:

for 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 — 8y
0
I was going to leave some comments but I needed to go to sleep, I've edited the answer for you. DevSean 270 — 8y
Ad

Answer this question