Model wont rotate when mouseclicked

Viewed 30
local handle = script.Parent.Door.Handle
local door = script.Parent.Door.Model

handle.ClickDetector.MouseClick:Connect(function()
    handle:SetPrimaryPartCFrame(handle:GetPrimaryPartCFrame() * CFrame.fromEulerAngles(0,math.rad(90), 0)
end)

This code is supposed to make a handle for a door rotate when "Mouseclick" Fires I cannot figure out the error

Script analysis states errors as being

(6,1) Expected ')' (to close '(' at line 5), got 'end'

(5,103) Expected 'end' (to close 'function' at line 4), got <eof>

2 Answers

The handle:SetPrimaryPartCFrame line has a lot going on and the error is telling you that you forgot to close a set of parentheses.

By breaking up some of the lines, you can keep track of the parentheses groups.

local targetCFrame = handle:GetPrimaryPartCFrame() * CFrame.fromEulerAngles(0, math.rad(90), 0)
handle:SetPrimaryPartCFrame(targetCFrame)

You forgot parantheses. If we take a look at it line by line with indentation, you'll see what's going wrong.

local handle = script.Parent.Door.Handle
local door = script.Parent.Door.Model

handle.ClickDetector.MouseClick:Connect(function()
    handle:SetPrimaryPartCFrame(
        handle:GetPrimaryPartCFrame(
            handle:GetPrimaryPartCFrame() * CFrame.fromEulerAngles(
                0, math.rad(90), 0
            )
        )
    -- There is a bracket missing here.
end)

So the correction is:

local handle = script.Parent.Door.Handle
local door = script.Parent.Door.Model

handle.ClickDetector.MouseClick:Connect(function()
    handle:SetPrimaryPartCFrame(
        handle:GetPrimaryPartCFrame(
            handle:GetPrimaryPartCFrame() * CFrame.fromEulerAngles(
                0, math.rad(90), 0
            )
        )
    )
end)
Related