Heyo! I have been wondering how I can make the camera just stay onto an object. I have a script that I learned from @Alvin_Blox’s plot system video. The only problem is that the camera won’t stay on the object.
local tweenservice = game:GetService("TweenService")
local player = game.Players.LocalPlayer
local camera = game.Workspace.Camera
local worldsselect = script.Parent:WaitForChild("WorldSelect")
local frame = worldsselect:WaitForChild("Frame")
local left = frame:WaitForChild("Left")
local right = frame:WaitForChild("Right")
local worlds = game.Workspace.Worlds
camera.CameraType = Enum.CameraType.Scriptable
local function getworlds()
local availableworlds = {}
for i, world in pairs(worlds:GetChildren()) do
table.insert(availableworlds, world.Name)
table.sort(availableworlds)
print(table.concat(availableworlds, ","))
end
return availableworlds
end
local tweeninfo = TweenInfo.new(
0.5,
Enum.EasingStyle.Quint,
Enum.EasingDirection.InOut,
0,
false,
0
)
local function cameratween(world)
local cf = CFrame.new(game.Workspace.Worlds:FindFirstChild(world).Position + Vector3.new(0,120,0), game.Workspace.Worlds:FindFirstChild(world).Position)
local tween = tweenservice:Create(game.Workspace.Camera, tweeninfo, {CFrame = cf})
tween:Play()
end
local worldtable = getworlds()
local index = 1
player.SelectedWorld.Value = worldtable[1]
cameratween(player.SelectedWorld.Value)
print("Got here")
left.MouseButton1Click:Connect(function()
if worlds:FindFirstChild("World "..index - 1) then
index -= 1
else
index = 4
end
player.SelectedWorld.Value = worldtable[index]
cameratween(worldtable[index])
end)
right.MouseButton1Click:Connect(function()
if worlds:FindFirstChild("World "..index + 1) then
index += 1
else
index = 1
end
player.SelectedWorld.Value = worldtable[index]
cameratween(worldtable[index])
end)
Where did I go wrong?