Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

CFrame script not functioning, no errors?

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)

1 comment

0

Put some prints in your code, it'll tell you where you went wrong.

1 answer

✓ Accepted answer
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.

2 comments

0

Note, when answering, try to include a description of what you did to make it work.

0

I was going to leave some comments but I needed to go to sleep, I've edited the answer for you.

This discussion is preserved as it was. New answers, comments, and votes are closed.