Sorry if this is too much, but you mind showing a short clip of it?
I’d prefer not to. Could you maybe inspect my code again?
I think the issue is that the button is pressed during a tween, but I don’t know how to solve that.
So maybe make the tween variable visible to the whole script?
local tween = nil
local forcestop = false
local tweeninfo = TweenInfo.new(
sceneTime,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
true,
0
)
function tween(camera1, camera2, ending)
if forcestop == false then
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = camera1.CFrame
tween = TweenService:Create(camera, tweeninfo, {CFrame = camera2.CFrame})
tween:Play()
tween.Completed:Wait()
if ending then
camera.CameraType = Enum.CameraType.Custom
local character = workspace:FindFirstChild(player.Name)
if character then
camera.CameraSubject = character
end
end
end
end
tween(cams.Camera1, cams.Camera2, false)
--wait(20)
tween(cams.Camera3, cams.Camera4, false)
--wait(20)
tween(cams.Camera5, cams.Camera6, false)
--wait(20)
tween(cams.Camera7, cams.Camera8, false)
--wait(20)
tween(cams.Camera9, cams.Camera10, true)
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if tween then
tween:Stop()
end
camera.CameraType = Enum.CameraType.Custom
local character = workspace:FindFirstChild(player.Name)
if character then
camera.CameraSubject = character
end
script.Parent.Parent.Parent.Enabled = false
forcestop = true
end)
Oh yeah, and make sure to merge these scripts into two so the tween variable can be accessed.
That’s a problem. The camera script is in StarterPlayerScripts, and the other one is in StarterGui. Would merging them cause any issues?
I mean you can move the one in StarterPlayerScripts to StarterGui, I think it wouldn’t hurt to do that.
Alright, I’ll try to merge them.
Putting those two blocks together makes the button do nothing on press.
What happens in detail:
The camera starts tweening.
After a couple seconds, the button appears.
On press, the button makes the UI disappear, but the camera remains the same.
Can I see your merged script? Thanks!
Merged script:
local TweenService = game:GetService("TweenService")
local cams = game.Workspace.Cameras
local done = false
local camera = game.Workspace.Camera
local sceneTime = 20
local tween = nil
local forcestop = false
local tweeninfo = TweenInfo.new(
sceneTime,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
true,
0
)
function tween(camera1, camera2, ending)
if forcestop == false then
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = camera1.CFrame
tween = TweenService:Create(camera, tweeninfo, {CFrame = camera2.CFrame})
tween:Play()
tween.Completed:Wait()
if ending then
camera.CameraType = Enum.CameraType.Custom
local character = workspace:FindFirstChild(player.Name)
if character then
camera.CameraSubject = character
end
end
end
end
tween(cams.Camera1, cams.Camera2, false)
--wait(20)
tween(cams.Camera3, cams.Camera4, false)
--wait(20)
tween(cams.Camera5, cams.Camera6, false)
--wait(20)
tween(cams.Camera7, cams.Camera8, false)
--wait(20)
tween(cams.Camera9, cams.Camera10, true)
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if tween then
tween:Stop()
end
camera.CameraType = Enum.CameraType.Custom
local character = workspace:FindFirstChild(player.Name)
if character then
camera.CameraSubject = character
end
script.Parent.Parent.Parent.Enabled = false
forcestop = true
end)
Readjust your code like this:
local TweenService = game:GetService("TweenService")
local cams = game.Workspace.Cameras
local done = false
local camera = game.Workspace.Camera
local sceneTime = 20
local tween = nil
local forcestop = false
local tweeninfo = TweenInfo.new(
sceneTime,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
true,
0
)
function tween(camera1, camera2, ending)
if forcestop == false then
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = camera1.CFrame
tween = TweenService:Create(camera, tweeninfo, {CFrame = camera2.CFrame})
tween:Play()
tween.Completed:Wait()
if ending and forcestop == false then
camera.CameraType = Enum.CameraType.Custom
local character = workspace:FindFirstChild(player.Name)
if character then
camera.CameraSubject = character
end
end
end
end
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if tween then
tween:Stop()
end
camera.CameraType = Enum.CameraType.Custom
local character = workspace:FindFirstChild(player.Name)
if character then
camera.CameraSubject = character
end
script.Parent.Parent.Parent.Enabled = false
forcestop = true
end)
tween(cams.Camera1, cams.Camera2, false)
--wait(20)
tween(cams.Camera3, cams.Camera4, false)
--wait(20)
tween(cams.Camera5, cams.Camera6, false)
--wait(20)
tween(cams.Camera7, cams.Camera8, false)
--wait(20)
tween(cams.Camera9, cams.Camera10, true)
For tween:Stop()
, I’m getting an error "Stop is not a valid member of Tween “Tween”
Sorry, replace the lines with tween:Stop() with tween:Cancel().
It works, but comes with this error:
On line 57: tween(cams.Camera3, cams.Camera4, false)
It gives the error “attempt to call an instance value”
The new script messes up the camera somehow, and makes it so that it doesn’t do anything past the 1st tween.
Also, on line 32 local character = workspace:FindFirstChild(player.Name)
, it says that the player is unknown, is that intentional?
That was not intentional, and the game.Players.LocalPlayer should exist for the whole time, I wonder why it doesn’t work, can you tell the the complete error message it showed in the output?
Players.RipPBB_TUD.PlayerGui.LoadingScreen.LoadingScreen3.Play.PlayMerge:58: attempt to call a Instance value - Client - PlayMerge:58
PlayMerge is the temporary name for the script I made.
After the camera goes from camera1 to camera2, it tweens to the player for some reason.
Ah, I got it, I just realized there is a variable tween and a function tween, so you might have to change the code to this:
local TweenService = game:GetService("TweenService")
local cams = game.Workspace.Cameras
local done = false
local camera = game.Workspace.Camera
local sceneTime = 20
local tween = nil
local forcestop = false
local tweeninfo = TweenInfo.new(
sceneTime,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
true,
0
)
function TweenFunction(camera1, camera2, ending)
if forcestop == false then
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = camera1.CFrame
tween = TweenService:Create(camera, tweeninfo, {CFrame = camera2.CFrame})
tween:Play()
tween.Completed:Wait()
if ending and forcestop == false then
camera.CameraType = Enum.CameraType.Custom
local character = workspace:FindFirstChild(player.Name)
if character then
camera.CameraSubject = character
end
end
end
end
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if tween then
tween:Cancel()
end
camera.CameraType = Enum.CameraType.Custom
local character = workspace:FindFirstChild(player.Name)
if character then
camera.CameraSubject = character
end
script.Parent.Parent.Parent.Enabled = false
forcestop = true
end)
TweenFunction(cams.Camera1, cams.Camera2, false)
--wait(20)
TweenFunction(cams.Camera3, cams.Camera4, false)
--wait(20)
TweenFunction(cams.Camera5, cams.Camera6, false)
--wait(20)
TweenFunction(cams.Camera7, cams.Camera8, false)
--wait(20)
TweenFunction(cams.Camera9, cams.Camera10, true)
After the 1st tween from camera1 to camera2, it goes to the player, and then back to the next camera.
When I click play, it will still tween my camera to the next camera.