How to not overuse if statement?

  1. What do you want to achieve? I want to make a skilltree system, when the player clicks a textbutton, it appears a skilltree of the character that shows everything to upgrade the character.

  2. What is the issue? The issue is: I know how to do that, although, I can’t figure out a way to avoid conditions just like “if” and “else”, I need to make just one skilltree GUI, so I don’t need to make that to every character on the game. I want to make it so I don’t necessarily need to write something like that:

if Character.Name == (CharacterSkillTree).Name then --Example
--Appear Gui Of The Character
elseif AnotherCharacter.Name == (AnotherCharacterSkillTree).Name then
--Appear Another Gui Of The Character

--And stuff..
  1. What solutions have you tried so far? Every solution.

The point is: How can I do something so I do not overuse “If” and don’t use each gui to each character?

8 Likes

If you mean that you don’t want to enter the name of each player, then this will help you.

Local Script

local Character = game.Player.LocalPlayer.Character

if Character.Name == ? then
  -- Condition
end
6 Likes

That’s not what I meant. Firstly, the Character is not the player, is a character on the game. I am making a Undertale game that you can upgrade characters, this character is the one you will upgrade, I just don’t want to make each SkillTree to each character, I need to make that so the game will “create” a skill tree based to the character skilltree, I don’t want to use If statement to see if the character name is that so he will create that.

4 Likes

If you need to get a different gui for all the skill trees, you can name them appropriately (to the skill tree’s name) and then use

-- "ui" is a container with all the ScreenGuis or whatever else
local skillTreeGui = ui:FindFirstChild(skillTree.Name)
4 Likes

Yea but I don’t want to make each skilltree to each character.

Like:

local SansSkill = game:GetService("StarterGui").SansSkillTree
local SansSkill2 = game:GetService("StarterGui").SansSkillTree2
local SansSkill3 = game:GetService("StarterGui").SansSkillTree3

if (CharacterThatHasBeenChooseToUpgrade) == SansSkill then
--Active skill
elseif (CharacterThatHasBeenChooseToUpgrade) == SansSkill2 then
--...

I want to make that optimized.

2 Likes

I’m a bit confused, do you mean like… Once you upgrade one skill, the next skill’s UI updates to show that it can be obtained?

3 Likes
local skills = {
Character1Name = function()
end,
Character2Name = function()
end, --etc.
}

--activate ability
skills[playerCharacterName]()
3 Likes

No, that is not what I mean. I am going to make that more clear.

2 Likes

Look, I need to make a skilltree system. I know how to do that, but I do not want to make multiple skilltree Guis to each character on the game.

Like, I have three characters on my game, I opened the first character stats, that there is a SkillTree textbutton that you can click on it and then it will appear a skilltree GUI Based on the Character Choosen. I want to make that so it opens the skilltree without a Statement and it creates a new skilltree GUI with the informations given.

But I don’t want to make Three skill Trees for Three characters.

Use a loop…? or a function. Well, a loop that runs a function, and have it set to change details through the functions parameters.

1 Like

It is ok to make three skilltree GUIs though, but I would use A LOT if statements.

That’s not it, guess you guys are not understanding.

You want a UI for every character but slightly different, correct? Use a loop to run through all the characters to create the UI and then inside the function (that the loop runs) use parameters to customize the UI.

1 Like

Can you show me an example if it is not a disturbance? Thank you!

local CreateUI = function(Color, Size, Name, TheParent) --These Parameters Can Be Changed To Whatever
	local NewFrame = Instance.new('Frame')
	NewFrame.BackgroundColor3 = Color
	NewFrame.Name = Name
	NewFrame.Parent = TheParent
end

local LoopingPlayers = game:GetService('Players'):GetPlayers() --Change This, I'm not sure where you are wanting to loop from
for __, Player in pairs(LoopingPlayers) do
	CreateUI(Color3.new(1, 1, 1), UDim2.fromScale(1, 1), 'Frame1', Player.PlayerGui)
end

I made this code server-sided btw, but the entire code can be configured

i recommended making 3 seperate Guis and naming them differently. Then put them in ReplicatedStorage. Now check for CharacterAdded event and clone the respective GUI for your character into PlayerGui

1 Like

Guys uh, I am not messing up with players. I am messing up with the game’s character, just like sans, chara, frisk, it is characters from Undertale game.

Reference my base code, keep in mind we are helping you, not creating a entire game for you. Please be more descriptive in one message and not slowly giving us more details. That creates a inconvenience and a undefined understanding within the conversation for all of us.

you can do smtg like this

local SanSkills = {}

SanSkills .SansSkill = game:GetService("StarterGui").SansSkillTree
SanSkills .SansSkill2 = game:GetService("StarterGui").SansSkillTree2
SanSkills .SansSkill3 = game:GetService("StarterGui").SansSkillTree3

SanSkills[CharacterThatHasBeenChooseToUpgrade] --your code (active skill thing)
3 Likes

Try using a folder for each character with the possible skills (values with the name of the skill and attributes for points, position, and link (previous skill you need to get it)) on the skill tree. When the skill tree is opened use an if statement to check what character the player is using (id use profileservice for saving data, completely unrelated but whatever man im giving u good advice,)

it would look something like

if plr.EquippedCharacter then
    local equippedCharacter = ReplicatedStorage.Characters[plr.EquippedCharacter]
    if equippedCharacter then
        for i, skill in pairs(equippedCharacter.Skills:GetChildren()) do
            --clone gui ish logic
            
           -- when the button is pressed/ player tries to get skill check if they own the last skill needed
            if plr.Skills[skill.Link] then
                 -- fire the server and do checks there or do whatever you want to do
            end
        end
    end
end

after checking their character, loop through every skill in the character folder, then simply clone every node and set it’s attributes, such as it’s position on the skill tree, link, etc

whenever someone is buying a skill, sanity check to make sure they have the correct character equipped,


im assuming you want something like this

oh yeah this is probably EXTREMELY unoptimal, im just giving you a base concept on how to achieve what you want dont accept advice from me im not a professional

ALTERNATIVE METHODS

  • Use super complex table stuffs
  • make a main module for handling characters and stuff, probably will require object-oriented programming or complex table stuffs
  • use hacky solutions relying on saved data (don’t do this lol)
2 Likes