I am making a sword fighting game and don't want the Intro GUI to go away until you select a sword. If you don't have a sword in your backpack the GUI will not disappear when you hit the "play" button and will instead bring up a GUI that tells the player they need to select a sword before continuing. The script works except it won't move the GUI that tells the player they need to select a sword into position. Any ideas?


-- Variables

local looky = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local char = player.Character
local hum = char:WaitForChild("Humanoid")
local storage = game:GetService("ReplicatedStorage")


-- This segment is what I'm having trouble with (near else)

script.Parent.Playbutton.MouseButton1Click:Connect(function()
local backpack = game.Players.LocalPlayer.Backpack

for i, child in pairs(backpack:GetChildren()) do
	
		if child:IsA("Tool") then
		
		storage.RemoteEvents.MobileOn:FireServer()
		script.Parent.Visible = false
		repeat
		wait()
		looky.CameraType = Enum.CameraType.Custom
		until looky.CameraType == Enum.CameraType.Custom
		
			else
				script.Parent.Parent.NoSword.Position = UDim2.new(0.321, 0,0.321, 0)
		end
	end
end)


	hum.Died:Connect(function()
		wait(5)
		
		storage.RemoteEvents.MobileOff:FireServer()
		
		repeat wait() 
		looky.CameraType = Enum.CameraType.Scriptable
		until looky.CameraType == Enum.CameraType.Scriptable
		
		repeat wait()
		looky.CFrame = game.Workspace.startingcamerapos.CFrame
		until looky.CFrame == game.Workspace.startingcamerapos.CFrame
		
		script.Parent.Visible = true
	end)

4 comments

0

Are there any errors that show up when you try running it?

0

If the backpack has no children then it will not run through that for loop. Since they do not have a sword yet I assume the backpack is empty so your for loop does not run.

0

I'd use :FindFirstChild() to find if there is a sword inside the players backpack.

0

Yes, he is right. If there are no swords in the backpack, then the script won't run. Make sure you have a sword in StarterPack so they spawn with a sword.