I had an idea of making a character selection with custom abilities based on the character and stuff and when i thought of it i came up with this:
My Idea:
when the player joins the game they get a gui with options of the characters. And based on the one they click it changes a string value’s value to the name of the chosen character
local CharValue = --value in the player
local UIS = game:GetService("UserInputService)
UIS.InputBegan:Connect(function()
if CharValue = Character1 then
--Ability one
end
end)
local CharValue = --value in the player again
local UIS = game:GetService("UserInputService)
UIS.InputBegan:Connect(function()
if CharValue = Character2 then
--Ability one
end
end)
The problem is when i add many characters many scripts will fire at once doing that check which i dont know if its practical.
Loop through a table for characters and their abilites, dont make individual scripts. And to prevent them from firing all at once, you can utilise :Disconnect() or some limiting system
Make the GUI with the character selections, then place them into StarterGUI. Once the player selects the character they want, the GUI will get disabled, and a remote event that fires the server needs to be fired. On the server, there needs to be a PlayerAdded script that adds the string value to the player. Once the server gets fired, it should change the string value’s value based on the character that was passed as a parameter by the client. You do not need UserInputService, just MouseButton1Click for the GUI with character selections
You could but its gonna be a big pain and will cause sphagetti code and i will still need the if statements to check which character the player chose which doesnt solve my problem and makes it worse
local CharValue -- whatever the value is
local UIS = game:GetService("UserInputService")
local Characters = {
Character1 = { -- char 1, you can rename the index to whatever
Ability1 = function()
--Ability one
-- make it do whatever here, for example increase speed
end,
Ability2 = function()
--Ability one
end,
},
Character2 = {
Ability1 = function()
--Ability one
end,
}
}
UIS.InputBegan:Connect(function()
for Character, Functions in Characters do
if CharValue == Character then
for _, AbilityFunction in Functions do
AbilityFunction() -- to activate the ability
end
end
end
end)
Here is a brief small example of what I mean, of course this can be changed up and edited as it is an example. Something like this will prevent you from making many scripts and more unnecessary connections