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

What should I be using to make the PrimaryPartCFrame change in the script work?

local part = script.Parent
local elevator = workspace.elevator
local secondfloor = workspace.mid1
local part1 = workspace.elevator.part1
local part2 = workspace.elevator.part2
local mid = elevator.mid

part2.ClickDetector.MouseClick:connect(function()
	if elevator:GetPrimaryPartCFrame = mid.CFrame then
	for i = 14.95, 3.65, -.1 do
	elevator:SetPrimaryPartCFrame(CFrame.new(5.8, i, 20.2))
		wait()
	end
	end
end)
	
part1.ClickDetector.MouseClick:connect(function()
	if elevator:PrimaryPartCFrame == secondfloor.CFrame then
	for i = 3.65, 14.95, .1 do
	elevator:SetPrimaryPartCFrame(CFrame.new(5.8, i, 20.2))
		wait()
	end
	end
end)

right about here V

if elevator:GetPrimaryPartCFrame = mid.CFrame then

i'm getting something that says "expected ( { or string got =" and i dont know what i should be using to get the script to work

1 comment

0

"PrimaryPartCFrame" isn't a valid. You're looking for :GetPrimaryPartCFrame() on lines 9 and 18.

1 answer

#There are many things wrong with this script.

That's not a great way to begin an answer? Is it... Well, there are many things that we can do to improve this script. The first thing we can do is tab it correctly. Tabbing is love, tabbing is life. Tabbing makes coding so much easier and understandable. We can look at how to tab and write beautiful code here.

So with that in mind, let's clean up this code.

local part 				= script.Parent
local elevator 			= workspace.elevator
local secondfloor    		= workspace.mid1
local part1 		        	= workspace.elevator.part1
local part2 				= workspace.elevator.part2
local mid 		        	= elevator.mid
-- Sorry about this, the SH editor doesn't want it to be straight.

part2.ClickDetector.MouseClick:connect(function()
	if elevator:GetPrimaryPartCFrame = mid.CFrame then
		for i = 14.95, 3.65, -.1 do
			elevator:SetPrimaryPartCFrame(CFrame.new(5.8, i, 20.2))
			wait()
		end
	end
end)

part1.ClickDetector.MouseClick:connect(function()
	if elevator:PrimaryPartCFrame == secondfloor.CFrame then
		for i = 3.65, 14.95, .1 do
			elevator:SetPrimaryPartCFrame(CFrame.new(5.8, i, 20.2))
			wait()
		end
	end
end)

There we go, nice, beautiful code. But this doesn't solve the problem.. does it? No. We still have a lot of problems to come. And I'm not talking about a convenience store lot, I'm talking about an Airport parking lot.


The First Problem

I feel as if this is a typo. A lonely little unnoticed typo. Must feel sad, so misplaced, so... forgotten, unseen... Anyways, now we have to kill it. This typo is located on line 9. You tried to compare 2 values with 1 equal sign. how sad, think about that other equal sign, all forgotten, alone. So let's help it out, and add another equal sign. But wait, There's more Even though there are no parameters, we still have to add an empty ().

-- line 9
if elevator:GetPrimaryPartCFrame() == mid.CFrame then

Now we go to going up.

Now I've taken some time to understand this script, y'know? And I've spotted a few other errors. One of them, is that you're trying to do PrimaryPartCFrame on line 18. That's not a thing. You forgot to Get, It's just waiting there, waiting to be gotten. And we also forgot the empty parameters.

if elevator:GetPrimaryPartCFrame() == secondfloor.CFrame then

The Finished code.

We're all done, its all done. Good, finally! Be happy! Our result is one beautiful apple pie!

local part 			= script.Parent
local elevator 		= workspace.elevator
local secondfloor = workspace.mid1
local part1 			 = workspace.elevator.part1
local part2 			 = workspace.elevator.part2
local mid 				 = elevator.mid

part2.ClickDetector.MouseClick:connect(function()
	if elevator:GetPrimaryPartCFrame() = mid.CFrame then
		for i = 14.95, 3.65, -.1 do
		elevator:SetPrimaryPartCFrame(CFrame.new(5.8, i, 20.2))
		wait()
		end
	end
end)

part1.ClickDetector.MouseClick:connect(function()
	if elevator:GetPrimaryPartCFrame() == secondfloor.CFrame then
		for i = 3.65, 14.95, .1 do
			elevator:SetPrimaryPartCFrame(CFrame.new(5.8, i, 20.2))
			wait()
		end
	end
end)

-- HungryJaffer, Used StackEdit as a MarkDown Editor.

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