Heyo Devforum! I have been developing my start menu for my game, but I have ran into a problem with my camera script. Whenever the player clicks the left or right button, the camera will return to the player and not just move onto the next object. If you don’t understand anything, I will be happy to explain, but here is the script I am using.
Camera script:
local tweenservice = game:GetService("TweenService")
local runservice = game:GetService("RunService")
local teleportservice = game:GetService("TeleportService")
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 enterbutton = worldsselect:WaitForChild("Enter")
local selectedtext = worldsselect:WaitForChild("GalaxySelected")
local worlds = game.Workspace.Worlds
local renderStepConnForCam
camera.CameraType = Enum.CameraType.Scriptable
print("Is 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)
if renderStepConnForCam then
renderStepConnForCam:Disconnect()
renderStepConnForCam = nil
end
local cf = CFrame.new(game.Workspace.Worlds:FindFirstChild(world).Position + Vector3.new(50,20,10), game.Workspace.Worlds:FindFirstChild(world).Position)
local tween = tweenservice:Create(workspace.Camera, tweeninfo, {CFrame = cf})
tween:Play()
local stopState = tween.Completed:Wait()
if stopState == Enum.PlaybackState.Cancelled then
return
end
renderStepConnForCam = runservice.RenderStepped:Connect(function()
workspace.CurrentCamera.CFrame = cf
end)
end
local worldtable = getworlds()
local index = 1
player.SelectedWorld.Value = worldtable[1]
cameratween(player.SelectedWorld.Value)
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)
enterbutton.MouseButton1Click:Connect(function()
if workspace.Worlds:FindFirstChild(worldtable[index]).TeleportId then
local teleportid = workspace.Worlds:FindFirstChild(worldtable[index]).TeleportId.Value
teleportservice:Teleport(teleportid, player)
else
print("There is no teleport id in "..worldtable[index])
end
end)
selectedtext.Text = "Selected World: "..player.SelectedWorld.Value
player.SelectedWorld.Changed:Connect(function()
selectedtext.Text = "Selected World: "..player.SelectedWorld.Value
end)