Script wont work as intended to

Im making this system where players can switch movesets by pressing Q or E. With the current code i have it half-works (if that makes sense)

Some of the code im using was provided to me by a member on the dev forum, @jbjgang2

Heres the main code

--MoveList is a table containing every move a player could use/has equipped
local UIS = game:GetService("UserInputService") or game:FindService("UserInputService")
local event = game.ReplicatedStorage.Events.DEvents.DEvent
local one = 1
local two = 2
local MoveList = {
	[1] = "Move1";
	[2] = "Move2";
}

local SelectedMove = 1 --Variable that keeps track of which move is currently selected, by default Move1 (the 1st value in the table) is selected

function ChangeMoves(InputObject, chat)
	if chat then return end
	
	if InputObject.KeyCode == Enum.KeyCode.E then
		SelectedMove = (SelectedMove >= #MoveList) and 1 or SelectedMove + 1

	elseif InputObject.KeyCode == Enum.KeyCode.Q then

		--For the other direction, we do the same thing except instead of adding we subtract
		--We also have to instead check if the SelectedMove is less than or equal to 1, and if it is we set it to the last value of the moveList, #MoveList
		SelectedMove = (SelectedMove <= 1) and #MoveList or SelectedMove - 1
	end

	--Now lets print the outcome see it in action,
	if InputObject.KeyCode == Enum.KeyCode.Q or InputObject.KeyCode == Enum.KeyCode.E then
		print(MoveList[SelectedMove])
		if MoveList[SelectedMove] == "Move1" then
			print("Mode 1")
			event:FireServer(one)
			
		end
		if MoveList[SelectedMove] == "Move2" then
			print("Mode 2")
			event:FireServer(two)
		end
	end

end

UIS.InputBegan:Connect(ChangeMoves)

Heres my Code

Code 1
local event = game:GetService("ReplicatedStorage").Events.DEvents.DEvent

event.OnServerEvent:Connect(function(plr, args)
	if args == 1 then

		local Char = plr.Character or plr.CharacterAdded:Wait()
			Instance.new("BoolValue", Char).Name = "CharacterSelected"
			local CharFolder = game:GetService("ServerStorage").Characters
			local folder = CharFolder.Determination:Clone()
			local DeterFolder = game:GetService("ReplicatedStorage").Determination
			local GUI = DeterFolder.HealthGui.Atch:Clone()
			GUI.Parent = Char:WaitForChild("Head")
			folder.Parent = plr.Backpack
			for _, v in pairs(folder:GetDescendants()) do
				if v:IsA("Script") or v:IsA("LocalScript") then
					v.Disabled = false
				end
		end
		local mode2 = plr.Backpack:WaitForChild("DMode2")
		if mode2 then
			mode2:Destroy()
		end
	end
	if args == 2 then
		local mode1 = plr.Backpack:WaitForChild("Determination")
		if mode1 then
			mode1:Destroy()
		end
		local Char = plr.Character or plr.CharacterAdded:Wait()
			Instance.new("BoolValue", Char).Name = "CharacterSelected"
			local CharFolder = game:GetService("ServerStorage").Characters
			local folder = CharFolder.Modes.DMode2:Clone()
			local DeterFolder = game:GetService("ReplicatedStorage").Determination
			local GUI = DeterFolder.HealthGui.Atch:Clone()
			GUI.Parent = Char:WaitForChild("Head")
			folder.Parent = plr.Backpack
			for _, v in pairs(folder:GetDescendants()) do
				if v:IsA("Script") or v:IsA("LocalScript") then
					v.Disabled = false
				end
		end
	end
end)
Code 2
local DEvent = game:GetService("ReplicatedStorage").Events.DEvents.DEvent
local DeterFolder = game:GetService("ReplicatedStorage").Determination

DEvent.OnServerEvent:Connect(function(plr, arg)
	local char = plr.Character or plr.CharacterAdded:Wait()

	if arg == 1 then
		local soul = DeterFolder.DeterSoul:Clone()
		local sword = DeterFolder.Sword:Clone()	
		local Shield = DeterFolder.Shield:Clone()
		local motor6D = Instance.new("Motor6D")
		local Smotor6D = Instance.new("Motor6D")
		local S2motor6D = Instance.new("Motor6D")	
		local hum = char:WaitForChild("Humanoid")	
		hum.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
		local torso = char:WaitForChild("Torso")
		local rArm = char:WaitForChild("Right Arm")
		local lArm = char:WaitForChild("Left Arm")
		soul.Parent = char
		Shield.Parent = char
		sword.Parent = char
		---------------------
		motor6D.Parent = torso
		motor6D.Part0 = torso
		motor6D.Part1 = soul
		---------------------
		Smotor6D.Parent =rArm
		Smotor6D.Part0 = rArm
		Smotor6D.Part1 = sword
		----------------------
		S2motor6D.Parent =lArm
		S2motor6D.Part0 = lArm
		S2motor6D.Part1 = Shield	
		motor6D.C0 = CFrame.Angles(math.rad(90),0,0) * CFrame.new(-0.47,-0.5,.5)
		S2motor6D.C0 = CFrame.new(0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1)
		S2motor6D.C1 = CFrame.new(0.100000001, 0, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
		Smotor6D.C0 = CFrame.new(0, -1, 0, 0.999999285, -8.71394835e-14, -1.02894433e-26, -8.71394835e-14, 1, 2.57629367e-13, -1.02894433e-26, 2.57629367e-13, 0.999999285)
		Smotor6D.C1 = CFrame.new(0, -0.100000001, 0, 8.71394835e-14, -1, -2.57629367e-13, 0.999999285, -8.71394835e-14, -1.02894433e-26, -1.02894433e-26, 2.57629367e-13, 0.999999285)
		motor6D.C0 = CFrame.new(0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1)
		motor6D.C1 = CFrame.new(-0.469999999, -0.49999997, -0.5, 1, 0, 0, 0, 0, -1, 0, 1, 0)
	end
	if arg == 2 then
		print("mode 2")
		local sword = char:FindFirstChild("Sword")
		local shield = char:FindFirstChild("Shield")
		
		if sword then
			sword:Destroy()
		end
		if shield then
			shield:Destroy()
		end
	end
end)
Code 3
local button = script.Parent
local blackScreen = script.Parent.Parent.Parent.BlackScreen
local player = game:GetService("Players").LocalPlayer

local TweenService = game:GetService("TweenService")
-------------------------------------
local tween2 = TweenService:Create(blackScreen.Frame, TweenInfo.new(2), {BackgroundTransparency = 1})
-------------------------------------
local event = game.ReplicatedStorage.Events.DEvents.DEvent
local one = 1
local parent = script.Parent.Parent

button.Activated:Connect(function()
	print("Determination Was Selected")
	tween2:Play()
	for i, v in pairs(parent:GetChildren()) do
		if v:IsA("ImageButton") then
			print(v.Name)
			v.Active = false
			----------------------------
			local tween = TweenService:Create(v, TweenInfo.new(.5), {ImageTransparency = 1})
			tween:Play()
		end
	end
	event:FireServer(one)
end)

Looking at the video, the modes switch but they wont switch back. So the system wont cycle through for some reason? I’m not sure why

Help is appreciated, thank you for your time

2 Likes

Have you seen anything in the developer console?

2 Likes

No, ive looked everywhere for a solution yet i havent found any yet

1 Like

Try to use the print method, see if anything comes out.

2 Likes

it wont print anything after mode 2 is selected

1 Like

Hey pyro, I took a look at your code but its hard to tell what’s wrong without the full context of what’s going on in the script. The input code I provided you with seems to be working fine, which leaves the other two pieces of code up for question. From what I see here I can’t tell you exactly what will fix it but there seems to be a lot of WaitForChild calls which could be causing your code to infinitely yield if the object its referencing doesn’t exist.

On the other hand, if somehow it is my input code that is giving you issues, and you cannot get the prints in that section of the code to output properly, shoot me a dm and ill try my best to work out the issue.

2 Likes