Hi, it’s my first time trying to make a fighting game with skill moves so I just wanted to know if this code is the best way I can execute with. If not, can someone please give me suggestions on how I should clean my messy code
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local abilities = script.Parent:WaitForChild("Abilities")
local skill1 = abilities.Skill1
local skill2 = abilities.Skill2
local skill3 = abilities.Skill3
local skill4 = abilities.Skill4
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
if character:WaitForChild("Humanoid").Health == 0 then return end
local currentSkill = character:WaitForChild("Humanoid").Skill
local sk1 = false
local sk2 = false
local sk3 = false
local sk4 = false
UserInputService.InputBegan:Connect(function(key)
--//SKILL 1
if key.KeyCode == Enum.KeyCode.One then
if sk1 == false then
sk1 = true
sk2 = false
sk3 = false
sk4 = false
skill1.UIStroke.Color = Color3.fromRGB(255, 218, 5)
skill2.UIStroke.Color = Color3.fromRGB(0, 0, 0)
skill3.UIStroke.Color = Color3.fromRGB(0, 0, 0)
skill4.UIStroke.Color = Color3.fromRGB(0, 0, 0)
end
end
--//SKILL 2
if key.KeyCode == Enum.KeyCode.Two then
if sk2 == false then
sk2 = true
sk1 = false
sk3 = false
sk4 = false
skill2.UIStroke.Color = Color3.fromRGB(255, 218, 5)
skill1.UIStroke.Color = Color3.fromRGB(0, 0, 0)
skill3.UIStroke.Color = Color3.fromRGB(0, 0, 0)
skill4.UIStroke.Color = Color3.fromRGB(0, 0, 0)
end
end
--//SKILL 3
if key.KeyCode == Enum.KeyCode.Three then
if sk3 == false then
sk3 = true
sk2 = false
sk1 = false
sk4 = false
skill3.UIStroke.Color = Color3.fromRGB(255, 218, 5)
skill2.UIStroke.Color = Color3.fromRGB(0, 0, 0)
skill1.UIStroke.Color = Color3.fromRGB(0, 0, 0)
skill4.UIStroke.Color = Color3.fromRGB(0, 0, 0)
end
end
--//SKILL 4
if key.KeyCode == Enum.KeyCode.Four then
if sk4 == false then
sk4 = true
sk2 = false
sk3 = false
sk1 = false
skill4.UIStroke.Color = Color3.fromRGB(255, 218, 5)
skill2.UIStroke.Color = Color3.fromRGB(0, 0, 0)
skill3.UIStroke.Color = Color3.fromRGB(0, 0, 0)
skill1.UIStroke.Color = Color3.fromRGB(0, 0, 0)
end
end
end)
To give an overview on how the code is supposed to work in game, whenever the player presses 1,2,3,4 button on the keyboard, they would equip a skill which will be ready to use. What I want is that they cannot use 2 or more of the same skills at the same time. So to do this, I made it so that there are booleans that can be set to false or true (vise-versa) if they use another skill prior to equipping a skill, it would only equip that recent skill.