Hello! I am making a system where when you click play, you go through an animation then you go to a different UI. I have another thing in the background where it switches camera angles and whenever you click one of the other buttons, it kills you and stuff and then it switches back to doing the camera angles! I hope you guys could help me fix this. Here is the script.
local tweenService = game:GetService("TweenService")
local camera = workspace.Camera
local cameraPart = workspace:WaitForChild("CameraPart")
local panningAngles = workspace:WaitForChild("PanningAngles")
local running = true
local clicked = false
-- UI references
local button = script.Parent.Parent
local buttonText = script.Parent
local sword1 = button.Parent:WaitForChild("Sword1")
local sword2 = button.Parent:WaitForChild("Sword2")
local title = button.Parent:WaitForChild("Title")
local howToPlayText = button.Parent:WaitForChild("HowToPlayText")
local mainFrame = button.Parent.Parent:WaitForChild("MainFrame")
local frame = button.Parent.Parent:WaitForChild("Frame")
local fadingFrame = button.Parent.Parent:WaitForChild("FadingFrame")
local clashSound = button:WaitForChild("SwordClash")
local dropSound = button:WaitForChild("Drop")
local music = button:WaitForChild("Music")
button.MouseEnter:Connect(function()
local module = require(game.ReplicatedStorage:WaitForChild("UIModule"))
buttonText.Text = "<" .. buttonText.Text .. ">"
module.PlayClickSound()
end)
button.MouseLeave:Connect(function()
buttonText.Text = "SPAWN"
end)
local function rotateAndDrop(sword, initialRotation, finalRotation, finalPos)
local rotateTween = tweenService:Create(
sword,
TweenInfo.new(0.3, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
{ Rotation = initialRotation }
)
local fallTween = tweenService:Create(
sword,
TweenInfo.new(0.3, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out),
{ Position = finalPos, Rotation = finalRotation }
)
rotateTween:Play()
rotateTween.Completed:Connect(function()
fallTween:Play()
end)
end
task.spawn(function()
while running do
for i = 1, 5 do
if not running then return end
local part = panningAngles:FindFirstChild("PanPart" .. i)
if part then
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = part.CFrame
end
for _ = 1, 20 do
if not running then return end
task.wait(0.1)
end
end
end
end)
button.MouseButton1Click:Connect(function()
running = false
sword1.Visible = true
sword2.Visible = true
howToPlayText.Visible = false
button.Visible = false
title.Visible = false
tweenService:Create(sword1, TweenInfo.new(0.2, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {
Position = UDim2.new(0.25, 0, 0.017, 0)
}):Play()
tweenService:Create(sword2, TweenInfo.new(0.2, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {
Position = UDim2.new(0.342, 0, 0.017, 0)
}):Play()
clashSound:Play()
task.wait(2.5)
rotateAndDrop(sword1, -30, -90, UDim2.new(0.25, 0, 0.4, 0))
rotateAndDrop(sword2, 30, 90, UDim2.new(0.342, 0, 0.4, 0))
task.wait(0.5)
dropSound:Play()
task.wait(2)
tweenService:Create(fadingFrame, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {
BackgroundTransparency = 0
}):Play()
task.wait(0.5)
mainFrame.Visible = false
frame.Visible = true
sword1.Visible = false
sword2.Visible = false
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = panningAngles.PanPart1.CFrame
task.wait(2)
tweenService:Create(fadingFrame, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {
BackgroundTransparency = 1
}):Play()
music:Play()
end)