Hello. I’m making a skill system. According to my idea, when you enter the game, a gui with skills appears. To equip a skill you need to click on it. I wanted to make the skill system standalone. I have a module that contains all the data about skills. In short, it allows you to create a new button and boolValue of a skill. The problem is that when you click on
button, she moves it to the player’s skills, but doesn’t want to go back.
I’m not very good at explaining but I’ll attach a photo.
local Skill = script.Parent
local ButtonSkill = Skill.TextButton
local Players: Players = game:GetService(“Players”)
local Player = Players.LocalPlayer
ButtonSkill.MouseButton1Click:Connect(function()
local Copy = script.Parent
print(“ssss”)
local Values = Player.PlayerGui.Skils.SkillsFrame.Values
for _, object in ipairs(Values:GetChildren()) do
if object:IsA(“BoolValue”) then
if object.Name == Skill.Name and object.Value == false then
object.Value = true
Copy.Parent = script.Parent.Parent.Parent.PlayerSkills
end
if object.Name == Skill.Name and object.Value == true then
object.Value = true
Copy.Parent = script.Parent.Parent.Parent.NotingSkills
end
end
end
end)
Unfortunately, this didn’t help. I was trying to do a lot with this script, so I forgot to set it to false. The fact is that after the first verification of the truth, he does nothing further.
In your script, if the value of the object is false, you set it to true.
If the value is true, you also set it to true.
I went ahead and optimized the code a little bit to make it easier to read.
ButtonSkill.MouseButton1Click:Connect(function()
local Copy = script.Parent
local Values = Player.PlayerGui.Skils.SkillsFrame.Values
for _, object in ipairs(Values:GetChildren()) do
if object:IsA("BoolValue") and object.Name == Skill.Name then
if object.Value == false then
object.Value = true
Copy.Parent = script.Parent.Parent.Parent.PlayerSkills
print("Equipped skill.")
else
object.Value = false
Copy.Parent = script.Parent.Parent.Parent.NotingSkills
print("Unequipped skill.")
end
end
end
end)
I used elseif and it seems to work fine use this script
local Skill = script.Parent
local ButtonSkill = Skill.TextButton
local Players: Players = game:GetService("Players")
local Player = Players.LocalPlayer
ButtonSkill.MouseButton1Click:Connect(function()
print("ssss")
local Values = Player.PlayerGui.Skils.SkillsFrame.Values
for _, object in ipairs(Values:GetChildren()) do
if object:IsA("BoolValue") then
if object.Name == Skill.Name and object.Value == false then
object.Value = true
Skill.Parent = script.Parent.Parent.Parent.PlayerSkills
elseif object.Name == Skill.Name and object.Value == true then
object.Value = false
Skill.Parent = script.Parent.Parent.Parent.NotingSkills
end
end
end
end)