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?
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