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

trying to make an elevator with the :SetPrimaryPartCFrame()? need help

So I'm trying to make a elevator with the :SetPrimaryPartCFrame() here is what i got so far

script.Parent.ClickDetector.mouseClick:connect(function()
	if script.Parent.Parent.elevatorfloor.Position.Y == 0.7 then
		repeat
			script.Parent.Parent.Parent.movingparts:SetPrimaryPartCFrame(CFrame.new(0,1,0))
			wait(0.1)
		until script.Parent.Parent.elevatorfloor.Position.Y == 25.7
	end
end)

it doesent work when i click the button brick nothing happends anyone got a fix?

1 answer

First of all, the event is called MouseClick - not "mouseClick". You're gonna have to match the case.

Secondly, the SetPrimaryPartCFrame function directly sets the model's CFrame - you're providing a fixed CFrame expecting it to increment the CFrame of the model. That is not how this function works, but you may look into the TranslateBy function - which is similar.

In order to effectively "increment" the CFrame of the model, you need to reference it's current CFrame using the GetPrimaryPartCFrame function, and then multiply by an offset CFrame.

--Define outside for easy access
local elevator = script.Parent.Parent.elevatorfloor
local movingparts = script.Parent.Parent.movingparts

script.Parent.ClickDetector.MouseClick:connect(function()
	if elevatorfloor.Position.Y == 0.7 then
		repeat
			--Get the current CFrame of the model
			local current = movingparts:GetPrimaryPartCFrame()
			local offset = CFrame.new(0,1,0) --Establish the offset
			--Set the CFrame
			movingparts:SetPrimaryPartCFrame(current*offset)
			wait(0.1)
		until 
			elevatorfloor.Position.Y >= 25.7
	end
end)

If this still doesn't work, it means the if statement on line 6 is getting in the way or the elevatorfloor's Position is already greater than 25.7

3 comments

0

i tried your script and i got this

1
  • Model:GetPrimaryCFrame() failed because no PrimaryPart has been set, or the PrimaryPart no longer exists. Please set Model.PrimaryPart before using this.
0

You have to set the PrimaryPart of your movingparts model prior to using the SetPrimaryPartCFrame function, because the function positions the model according to the PrimaryPart's location.

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