Way to improve my code for a Jojo game?

I’m making a stand game, is there any way to improve this code?

local followPlayer2 = false
local standValue2 = false
local quoteEnd2 = false
local kickPlayer2 = false
local timeStopped2 = false
local standOut2 = false

local quoteTable2 = {
}
local rollAnimation2 = Instance.new("Animation")
rollAnimation2.AnimationId = "rbxassetid://5023224010"


local poseEnabled2 = false


game:GetService("UserInputService").InputBegan:Connect(function(input,gameProccessed)
	if gameProccessed == false then
	if input.UserInputType == Enum.UserInputType.Keyboard then
			if input.KeyCode == Enum.KeyCode.F then
			if game.Players.LocalPlayer.standValue.Value == "RigTest" then
				local BodyThrust = Instance.new("BodyThrust",game.Players.LocalPlayer.Character.HumanoidRootPart)
				BodyThrust.Force = Vector3.new(math.huge,math.huge,math.huge)
			end
			if game.Players.LocalPlayer.standValue.Value == "Forgotten Memory" then
				timeStopped2 = not timeStopped2
				if timeStopped2 == true then
					game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name.."2").PunchAnimation:FireServer("Ability")
				end
					if timeStopped2 == false then
						game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name.."2").PunchAnimation:FireServer("AbilityStop")
						end
				end
		end
			if kickPlayer2 == false then
			if game.Players.LocalPlayer.standValue.Value ~= "Long story short" then
if input.KeyCode == Enum.KeyCode.R then
			kickPlayer2 = true
			if kickPlayer2 == true then
				followPlayer2 = "Kick"
				game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name.."2").KickAnimation:FireServer("Play")
				wait(1)
													followPlayer2 = true
				wait(1)
							kickPlayer2 = false
						end
		end
		end
		end
		end
		if game.Players.LocalPlayer.standValue.Value ~= "Long story short" then
		if input.KeyCode == Enum.KeyCode.N then
			if quoteEnd2 == false then
			game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name.."2").SayQuote:FireServer(quoteTable2[math.random(1,#quoteTable2)])
			quoteEnd2 = true
			wait(2)
			quoteEnd2 = false
			end
		end
		end
	if game.Players.LocalPlayer.standValue.Value ~= "Long story short" then
		if input.KeyCode == Enum.KeyCode.E then
			followPlayer2 = "Punch"
				game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name.."2").PunchAnimation:FireServer("Play")
			end
		end
	if input.KeyCode == Enum.KeyCode.Q then
		if game.Players.LocalPlayer.standValue == "RigTest" then
			followPlayer2 = "Other"
		end
		if game.Players.LocalPlayer.standValue ~= "RigTest" then
				followPlayer2 = not followPlayer2
				end
			game:GetService("RunService").RenderStepped:Connect(function()
				if followPlayer2 == true then
					game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name.."2").HumanoidRootPart.Anchored = false
				game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name.."2").HumanoidRootPart.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame * CFrame.new(-2,2,3)
				end
				if followPlayer2 == false then
					game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name.."2").HumanoidRootPart.CFrame = CFrame.new(-6.5, 63, 53, 1, 0, 0, 0, 1, 0, 0, 0, 1)
					game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name.."2").HumanoidRootPart.Anchored = true
				end
				if followPlayer2 == "Punch" then
					game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name.."2").HumanoidRootPart.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame * CFrame.new(-0.5,0,-3)
					end
				if followPlayer2 == "Kick" then
					game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name.."2").HumanoidRootPart.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame * CFrame.new(-0.5,0,-3)
				end
			if followPlayer2 == "Other" then
				game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name.."2").HumanoidRootPart.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame * CFrame.new(-2,2,3)
			end
			end)
		end
		end
	end)
game:GetService("UserInputService").InputEnded:Connect(function(input2)
	if input2.UserInputType == Enum.UserInputType.Keyboard then
		if game.Players.LocalPlayer.standValue.Value ~= "Long story short" then
			if input2.KeyCode == Enum.KeyCode.E then
					 
			followPlayer2 = true
				game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name.."2").PunchAnimation:FireServer("Stop")
		end
	end
	end
end)

game.Players.LocalPlayer.Chatted:Connect(function(message)
	if message:lower() == "become/" then
		game.Workspace.CurrentCamera.CameraSubject = game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name.."2").Humanoid
	end
end)

while true do
	wait(3)
	game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name.."2").PunchAnimation:FireServer("Float")
end

This check is unnecessary, because if the keycode was f it would already be coming from a keyboard.

Try using more elseifs because then the code won’t run unnecessary if statements.

2 Likes

First off, This isn’t a must but i can see u are using runservice, Player and UserInputService. Instead of saying game:GetService() then u could say local UserInputService = game:GetService(“UserInPutService”) and the same for runservice and localplayer. Just incase u dont really think this is worth it then it could come in handy when u want to add more to ur code instead of using game:GetService()

It would be helpful if you could first outline the details of your post. Recently there’s been a string of threads asking for improvements to code and just posting everything without acknowledging that the most important part of a review is context. Please see our category guidelines.

Terminology like “stand” is unclear - I don’t know what this means. I also don’t know what your code is intended to do or what it is for and even just reading it only gives me a vague understanding of what you want and in what way you’re looking for improvements. What dissatisfies you?