Hey, developers!
I have a big issue that I’ve been unable to fix in the past day. In my game, Megalodon Survival, I’ve been trying to replace a GUI transition with a transition that rotates around the map before teleporting players.
The issue I’ve come across is that I can’t seem to play this tween more than once… it’s fired for all clients from the server using a remote event that plays the tween but it simply won’t play for any transitions after the first time it’s been fired. If I enable a loop, I can’t manage to stop the camera tween with anything as it goes on infinitely.
You can take a look at the main script which fires the events, the camera script, and a preview of what it looks like during the transition.
Main:
--CAMERA TEST
game.Lighting.DepthOfField.Enabled = false
transitionFunction:FireAllClients({Action = 'Play'})
wait(10)
game.Lighting.DepthOfField.Enabled = false
transitionFunction:FireAllClients({Action = 'Stop'})
--CAMERA TEST
Camera:
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local target = workspace:FindFirstChild("transitionCamera") -- The object to rotate around
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local rotationAngle = Instance.new("NumberValue")
local tweenComplete = false
local cameraOffset = Vector3.new(0, 64, 384) --0, 10, 12
local rotationTime = 10 -- Time in seconds
local rotationDegrees = 360
local rotationRepeatCount = 0 -- Use -1 for infinite repeats
local lookAtTarget = true -- Whether the camera tilts to point directly at the target
local plr = game.Players.LocalPlayer
local transitionFunction = game.ReplicatedStorage:WaitForChild('Transition')
transitionFunction.OnClientEvent:Connect(function(args)
local function updateCamera()
if not target then return end
camera.Focus = target.CFrame
local rotatedCFrame = CFrame.Angles(0, math.rad(rotationAngle.Value), 0)
rotatedCFrame = CFrame.new(target.Position) * rotatedCFrame
camera.CFrame = rotatedCFrame:ToWorldSpace(CFrame.new(cameraOffset))
if lookAtTarget == true then
camera.CFrame = CFrame.new(camera.CFrame.Position, target.Position)
end
end
-- Set up and start rotation tween
local tweenInfo = TweenInfo.new(rotationTime, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, rotationRepeatCount)
local tween = TweenService:Create(rotationAngle, tweenInfo, {Value=rotationDegrees})
tween.Completed:Connect(function()
tweenComplete = true
end)
if args.Action == 'Play' then
tween:Play()
end
if args.Action == 'Stop' then
tween:Cancel()
end
-- Update camera position while tween runs
RunService.RenderStepped:Connect(function()
if tweenComplete == false then
updateCamera()
end
end)
end)
Preview:
https://gyazo.com/5252c542c59078ca59a148fa5dd16ae9
I hope I can get some help on this!!! If you can help, I really appreciate it.