Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Skill Tree Requeriments is not working like planned?

I'm about to launch my first game in roblox and tried to do something different, so I made a script that makes a skill tree, then the player checks all the created butts, gets the information in ReplicatedStorage and then the game tells you 1-3 requirements to that the skill is available. It took me 1 full day for me to program this and the only problem, and that only 1 of the 3 requirements is required for the ability to be unlocked.

This part verify if all 3 requeriments color are green and turn the button green if it is , but the game only need one complete requirement for make the button green.

				
for g , h in pairs(Informations.Requirements:GetChildren()) do
	 if h.TextColor3 == Color3.new(85/255, 255/255, 127/255)  then
		Informations.Unlock.BackgroundColor3 = Color3.new(85/255, 255/255, 127/255)
	elseif  h.TextColor3 ~= Color3.new(85/255, 255/255, 127/255) then
		Informations.Unlock.BackgroundColor3 = Color3.new(1,0,0)
	end
end

1 answer

✓ Accepted answer

The for loop can only iterate through the requirements of the skill one at a time. This means that if it finds one valid skill requirement, it will continue to make the skill available regardless of the other requirements' statuses. You could make a variable outside of the for loop that keeps track of whether all the requirements are valid so that the for loop takes all the requirements into account.

local found = true
for g , h in pairs(Informations.Requirements:GetChildren()) do
     if h.TextColor3 ~= Color3.new(85/255, 255/255, 127/255)  then
		Informations.Unlock.BackgroundColor3 = Color3.new(1,0,0)
		found = false
		break
	end
end
if found then 
	for g , h in pairs(Informations.Requirements:GetChildren()) do
		Informations.Unlock.BackgroundColor3 = Color3.new(85/255, 255/255, 127/255)  
	end 
end
  

1 comment

0

Its magic!

This discussion is preserved as it was. New answers, comments, and votes are closed.