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

Why wont this code work? It Should move the camera after a part is clicked.

Asked by 4 years ago
script.Parent.MouseClick:Connect(function()
local Player = game.Players.LocalPlayer      
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera
local Cameras = workspace:WaitForChild('Camera')
local CameraPart1 = Cameras:WaitForChild('CameraPart1')
local CameraPart2 = Cameras:WaitForChild('CameraPart2')

repeat wait()
    Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CFrame = CameraPart1.CFrame

for Num = 0,1,.01 do
    Camera.CFrame = CameraPart1.CFrame:lerp(CameraPart2.CFrame,Num)
    wait()
end

end)

I have this in a local script that is inside of a Clickdetector. When I click the button in the game it does not do anything or even output anything. This script should set up the camera and then move it where I want it. I am new to Roblox Lua and got this by watching a youtube video. I would appreciate some help.

1 answer

Log in to vote
1
Answered by
DanzLua 2879 Moderation Voter Community Moderator
4 years ago

LocalScripts not parent to something connected to the player such as the playergui or their character won't run.

You'll need to parent this localscript a place like StarterPack for it to work.

Ad

Answer this question