UI System not Working

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)

1 Like

The script is really hard-to-see. Try making module scripts that handle main parts of the script. Also, this may help fix your problem, as it makes your code cleaner.

In addition, you shouldn’t be doing that. Requiring the same module multiple times is not needed; you can just require it on the start of the script.

I recommend that you disconnect the connection; use Once instead.

That module script just handles some sounds.

still, it’s not advised for you to require many times a module you could simply required outside of the connection

Thank you, but do you know how to fix my script so it doesn’t do what I described it did?

What’s the problem with the script? What’s going wrong?

Did you read the post above?
ihate30characterlimit

I read it, but where’s the problem? (I’m dumb sorry)

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!

It switches to different buttons you can choose from (Team buttons) and when you click them you die and stuff but after a second, it goes back to the pan angles.

So you don’t want the camera to go back to the normal angles?

I want the camera to go back to the regular player angle.

So why don’t you store the camera CFrame previously, and then do Camera.CFrame = originalCFrame when you need?

breh, you have to be kidding me. Let me test it rq.

1 Like

So did it work? If it didn’t work, it may be better for you to store only the orientation of the camera.CFrame and then set it later when the player respawns.

wait, i’m kinda dumb when it comes to camera stuff but I do camera.CFrame = then I forget.

Actually, this may help you:

Sorry for the late response but I’ve been doing that.

So, did it work? If it didn’t, tell me the problem.