Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago
Edited by OldPalHappy 7 years ago

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

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

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

0
i tried your script and i got this popthecorn145 16 — 7y
1
- Model:GetPrimaryCFrame() failed because no PrimaryPart has been set, or the PrimaryPart no longer exists. Please set Model.PrimaryPart before using this. popthecorn145 16 — 7y
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. Goulstem 8144 — 7y
Ad

Answer this question