How would I make a skill tree function if a skill is unlocked

I want to make it so if you unlocked a skill you’ll go faster I’ve already made it so you can unlock the skills but I don’t know how I would make it if I unlock agility the player will go faster without using if statements for example

if  Skills["Character SkillTree"]["Agility1"]["Unlocked"] then
Character.Humanoid.Walkspeed = 20
elseif Skills["Character SkillTree"]["Agility2"]["Unlocked"] then
Character.Humanoid.Walkspeed = 25
--ect.
end

because it would be a messy
is there another method or way to do this?

local Skills = {
	["Character SkillTree"] = {
		Character = {
			PointsRequired = 0,
			SkillsNeeded = "",
			Unlocked = true;
			Info = "This is your character."
		};
		Agility1 = {
			PointsRequired = 1,
			SkillsNeeded = "Character";
			Unlocked = false;
			Info = "Unlock to gain more dash distance and running speed.";
		};
		Agility2 = {
			PointsRequired = 1,
			SkillsNeeded = "Agility1";
			Unlocked = false;
			Info = "Unlock to gain more dash distance and running speed.";
		};
}
}
1 Like

One idea I believe could work is for each skill in the tree you put another property that contains a function that is ran when you unlock a skill. Example

Agility1 = {
	PointsRequired = 1,
	SkillsNeeded = "Character";
	Unlocked = false;
	Info = "Unlock to gain more dash distance and running speed.";
	OnUnlock = function(char)
		char.Humanoid.Walkspeed = 20
	end
};

And then in your code that unlocks skills in a skill tree, just do

Skills["Character SkillTree"]["Agility1"]["OnUnlock"](Character)

After the code that unlocks the skill. This is an example using Agility1, you may have to change it around for other skills

3 Likes