I found a tutorial, check it out and see if it works for you
Otherwise, one way you can utilize an object-oriented programming structure(OOP) for a skill structure as this post suggests.
I prefer using @Kironte OOP template which you can structure a skill object like this:
-- Initialize Object Class
local Package = script:FindFirstAncestorOfClass("Folder")
local Object = require(Package.BaseRedirect)
local Skill = Object.new("Skill")
function Skill.new(Name,UnlockCost,Requirements)
local obj = Skill:make()
--Create a table to store what previous skill objects are required
obj.Requirements = Requirements
obj.UnlockCost = UnlockCost
obj.Name = Name
obj.IsUnlocked = false
return obj
end
--Function for a skill object
--Checks through the objects within the Skill's Requirement table unlocked property
--If a single skill is not unlocked yet then the check fails
function Skill:CheckRequirementsAndUnlock()
local allPreviousSkillsUnlocked = true
for _ , PreviousSkillsRequired in pairs(self.Requirements) do
if not PreviousSkillsRequired.IsUnlocked then
allPreviousSkillsUnlocked = false
end
end
if allPreviousSkillsUnlocked then
--Do stuff now that it has been confirmed that the
-- previous skills are all unlocked
end
end
return Skill
Overall, the question is pretty abstract and there are plenty of better ways to do a skill system it’s best to plan it out first what a skill object needs one by one like so:
Skill object will need:
-
Prerequisite skills what skills you will need before unlocking this one
-
Unlock conditions/costs
-
Method to tell GUI that the skill is unlocked and change GUI as so
-
Method to give the player the actual ability/stats bonus
And then you can spice it up by working with skill inheritance so you can make different types of skills like:
-
Passive stats skill just gives flat out stat bonuses
-
Active skills that handle the player actions in the world.
fundamentally skills trees are just an extensive boolean check. I don’t think I explained well so please ask me more questions on whatever I just wrote.