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

Part does nothing when clicked on to activate the camera manipulation, how do I fix it?

Asked by 8 years ago

Hello, What I'm trying to create is when a player clicks on a part, which would activate the MouseClick event on the ClickDetector, and when clicked, it changes the camera position to the part, and rotates around it, for some reason when I tried it out, nothing happens... Here is the script that I was talking about...

Note: The Child inside the Part is the Local Script and the ClickDetector.

local target = script.Parent
local camera = game.Workspace.CurrentCamera

local angle = 0
local isPlaying = false

script.Parent.ClickDetector.MouseClick:connect(function()   

    camera.CameraType = Enum.CameraType.Scriptable
    camera.CameraSubject = target

    isPlaying = true    

end)

while isPlaying do
    camera.CFrame = CFrame.new(target.Position)
                    * CFrame.Angles(0, angle, 0)
                    * CFrame.new(0, 3, 5)

    angle = angle + math.rad(1)

    wait()  

end

Thank you!

~NanotechSci

1 answer

Log in to vote
1
Answered by 8 years ago

Hi Nano! Your issue here is that the while loop checks for variable "isPlaying" once, and since isPlaying returns false, the loop will end and will not be repeated. Without going into the heavier stuff, I'd recommend you place your while loop inside of your ClickDetector event!

Nice work!

0
Hello! I have tried putting the while loop inside the event, but nothing happens :( NanotechSci 40 — 8y
Ad

Answer this question