UI is not working for seemingly no reason

For some reason my UI script isn’t working, no errors or anything, except sometimes it shows this.
image

The script:

local uis = game:GetService("UserInputService")
local p = game.Players.LocalPlayer
local par = script.Parent.Root
local vis = false
local cam = workspace.CurrentCamera

local deb = false
p.CharacterAdded:Wait()
local ws = p.Character.Humanoid.WalkSpeed
local jp = p.Character.Humanoid.JumpPower

local TweenService = game:GetService("TweenService")
local function a(Object, Length, Style, Direction, Properties)
	local Tween = TweenService:Create(
		Object,
		TweenInfo.new(Length, Enum.EasingStyle[Style].Value, Enum.EasingDirection[Direction].Value),
		Properties
	)

	Tween:Play()
end

uis.InputBegan:Connect(function(k,gpe)
	if gpe then return end
	if deb then return end
	if k.KeyCode == Enum.KeyCode.C then
		task.wait(2)
		deb = true
		print("hi")
		if vis == false then
			par.Visible = true
			
			par.InfoFrame.Position = UDim2.new(-0.3, 0,0, 0)
			par.MenuFrame.Position = UDim2.new(-0.3, 0,0.395, 0)
			par.StatFrame.Position = UDim2.new(0.571, 0,0.5, 0)
			par.ItemFrame.Position = UDim2.new(0, 0,0, 0)
			spawn(function()
				a(par.InfoFrame, 0.5, "Cubic", "Out", {Position = UDim2.new(0.015, 0,0, 0)})
				task.wait(0.1)
				a(par.MenuFrame, 0.5, "Cubic", "Out", {Position = UDim2.new(0.015, 0,0.395, 0)})
				task.wait(0.6)
				vis = true
				deb = false
			end)
			
			p.Character.Humanoid.WalkSpeed = 0
			p.Character.Humanoid.JumpPower = 0
			spawn(function()
				wait(.05)
				cam.CameraType = Enum.CameraType.Fixed
			end)
			
		else
			--[[par.InfoFrame.Position = UDim2.new(0.045, 0,0.1, 0)
			par.MenuFrame.Position = UDim2.new(0.045, 0,0.312, 0)]]
			spawn(function()
				a(par.InfoFrame, 0.5, "Cubic", "In", {Position = UDim2.new(-0.3, 0,0, 0)})
				task.wait(0.1)
				a(par.MenuFrame, 0.5, "Cubic", "In", {Position = UDim2.new(-0.3, 0,0.395, 0)})
				task.wait(0.1)
				a(par.StatFrame, 0.5, "Cubic", "In", {Position = UDim2.new(1.5, 0,0.5, 0)})
				a(par.ItemFrame, 0.5, "Cubic", "In", {Position = UDim2.new(1, 0,0, 0)})
			end)
			task.wait(0.7)
			par.Visible = true
			par.ItemFrame.Visible = false
			par.StatFrame.Visible = false
			vis = false
			deb = false
			p.Character.Humanoid.WalkSpeed = ws
			p.Character.Humanoid.JumpPower = jp
			cam.CameraType = Enum.CameraType.Custom
			
			--needed this for the inventory
			
			par.ItemFrame.Main:ClearAllChildren()
			local uilist = Instance.new("UIListLayout", par.ItemFrame.Main)
			local uistroke = Instance.new("UIStroke", par.ItemFrame.Main)
			uistroke.Thickness = 6
			uistroke.LineJoinMode = Enum.LineJoinMode.Bevel
			uistroke.Color = Color3.new(1,1,1)
			
		end
	end
end)

par.MenuFrame.ButtonsList.Item.MouseEnter:Connect(function()
	a(par.MenuFrame.ButtonsList.Item, 0.1, "Linear", "In", {TextColor3 = Color3.new(1,1,0)})
	par.MenuFrame.ButtonsList.Item.Text = ">ITEM"
	local sound = game.ReplicatedStorage.Sounds.ButtonHover:Clone()
	sound.Parent = game.Players.LocalPlayer.Backpack["Music/Sounds"]
	sound:Destroy()
end)
par.MenuFrame.ButtonsList.Item.MouseLeave:Connect(function()
	a(par.MenuFrame.ButtonsList.Item, 0.1, "Linear", "In", {TextColor3 = Color3.new(1,1,1)})
	par.MenuFrame.ButtonsList.Item.Text = "ITEM"
end)

par.MenuFrame.ButtonsList.Stat.MouseEnter:Connect(function()
	a(par.MenuFrame.ButtonsList.Stat, 0.1, "Linear", "In", {TextColor3 = Color3.new(1,1,0)})
	par.MenuFrame.ButtonsList.Stat.Text = ">STAT"
	local sound = game.ReplicatedStorage.Sounds.ButtonHover:Clone()
	sound.Parent = game.Players.LocalPlayer.Backpack["Music/Sounds"]
	sound:Destroy()
end)
par.MenuFrame.ButtonsList.Stat.MouseLeave:Connect(function()
	a(par.MenuFrame.ButtonsList.Stat, 0.1, "Linear", "In", {TextColor3 = Color3.new(1,1,1)})
	par.MenuFrame.ButtonsList.Stat.Text = "STAT"
end)

par.MenuFrame.ButtonsList.Cell.MouseEnter:Connect(function()
	a(par.MenuFrame.ButtonsList.Cell, 0.1, "Linear", "In", {TextColor3 = Color3.new(1,1,0)})
	par.MenuFrame.ButtonsList.Cell.Text = ">CELL"
	local sound = game.ReplicatedStorage.Sounds.ButtonHover:Clone()
	sound.Parent = game.Players.LocalPlayer.Backpack["Music/Sounds"]
	sound:Destroy()
end)
par.MenuFrame.ButtonsList.Cell.MouseLeave:Connect(function()
	a(par.MenuFrame.ButtonsList.Cell, 0.1, "Linear", "In", {TextColor3 = Color3.new(1,1,1)})
	par.MenuFrame.ButtonsList.Cell.Text = "CELL"
end)

par.MenuFrame.ButtonsList.Item.MouseButton1Click:Connect(function()
	par.ItemFrame.Visible = true
	par.StatFrame.Visible = false
	
	local sound = game.ReplicatedStorage.Sounds.ButtonClick:Clone()
	sound.Parent = game.Players.LocalPlayer.Backpack["Music/Sounds"]
	sound:Destroy()
end)

par.MenuFrame.ButtonsList.Stat.MouseButton1Click:Connect(function()
	par.ItemFrame.Visible = false
	par.StatFrame.Visible = true

	local sound = game.ReplicatedStorage.Sounds.ButtonClick:Clone()
	sound.Parent = game.Players.LocalPlayer.Backpack["Music/Sounds"]
	sound:Destroy()
end)

Not enough to test anything here… Blind guess: try a task.wait(4) at the top