So here is the script I made and instead of doing line 1, 2 and 3 again can I look for the word Is in the value name and make that value false? If you can then can you help me on understanding to do it? I'm looking for a shortcut because soon I will add way more than 4 perks and would help a lot.
local TheName = -- Player's username while true do wait() if game.Players:FindFirstChild(TheName).PerkValues.DoubleJumpGlideIs.Value == true then game.Players:FindFirstChild(TheName).PerkValues.MoreHealthIs.Value = false -- line 1 game.Players:FindFirstChild(TheName).PerkValues.DoubledMoneyIs.Value = false -- line 2 game.Players:FindFirstChild(TheName).PerkValues.DoubledDamageIs.Value = false -- line 3 print("All other perks Unequipped") else print("Hi") wait(5) end end
But in the end it will likely take more space than your code already does. But it is good for the sake of future proofing your code (say you add another "Is" value, this would already cover that).
Now lets get some code down:
local perks = game.Players:FindFirstChild(TheName).PerkValues:GetChildren() for i=1,#perks do end
Now lets see if our instance has a name with
"Is" in it.
local perks = game.Players:FindFirstChild(TheName).PerkValues:GetChildren() for i=1,#perks do if string.match(perks[i].Name, "Is") ~= nil then end end
Basically what we did is create an if statement and then matched the current perk's name with the string
"Is". Since this returns ether the matched string (if it was found) or nil (if nothing was found), we can't treat it as a simple bool statement.
~= we see if the result is not equal to nil. So if
string.match returns nil,
~= will return false; if
string.match returns anything but nil,
~= returns true.
Thats really it, place your value modifying code (
value = false) inside the if statement and your off.