How to make gui buttons change upon stat change?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    For Quirk Buttons to get replaced upon quirk (stat) change

  2. What is the issue? Include screenshots / videos if possible!
    Players have to rejoin when they change quirk in order for buttons to get replaced.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried many edits/Variations of this script,

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

wait(0.5)
local plr = game.Players.LocalPlayer
local qu = plr:WaitForChild("PlayerStats",math.huge).DF
local Skill = script.Parent -- Parent is a TextButton inside a SreenGui
local uis = game:GetService("UserInputService")
if uis.TouchEnabled == true and uis.KeyboardEnabled == true then
	script.Parent.Parent.Enabled = true
else
script.Parent.Parent.Enabled = true	
end

for i = 1,1 do
	if qu.Value == "OneForAll" then
		Skill.OneForAll.Visible = true

	end

	if qu.Value == "Electrification" then
		Skill.Electrification.Visible = true

	end
	if qu.Value == "DekuOneForAll" then
		Skill.DekuOneForAll.Visible = true

	end
	end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Check if the qu value changed by using GetPropertyChangedSignal

qu:GetPropertyChangedSignal("Value"):Connect(function()
    -- put your if statements here
end)

The reason your code didn’t work is you started the for loop from 1, I don’t recommend you do that since it’s a bad practice.

Appreciate your reply. Tried it but didn’t work.

wait(0.5)
local plr = game.Players.LocalPlayer
local qu = plr:WaitForChild("PlayerStats",math.huge).DF
local Skill = script.Parent -- Parent is a TextButton inside a SreenGui
local uis = game:GetService("UserInputService")
if uis.TouchEnabled == true and uis.KeyboardEnabled == true then
	script.Parent.Parent.Enabled = true
else
script.Parent.Parent.Enabled = true	
end

qu.Changed:Connect(function()
	if qu.Value == "OneForAll" then
		Skill.OneForAll.Visible = true

	end

	if qu.Value == "Electrification" then
		Skill.Electrification.Visible = true

	end
	if qu.Value == "DekuOneForAll" then
		Skill.DekuOneForAll.Visible = true

	end
end

So, the issue with both attempts so far is that player starts off with no buttons, then when changing quirk (stat) the buttons do not disappear to get replaced and then stack on top of each other.


QuValue

So you want the new quirk to be added to this random table thing?

No, all the quirks are already in. Issue is you have to exit and rejoin for Gui buttons to appear correctly.

Please show me the code for this

Its same as one I posted before, I just removed most to keep shorter

Try removing the for loop, and I think using a table would be better personally.

With or without loop makes no difference. Appreciate the feedback, will see how to replace/convert to table.

Table example:

local quirks = {
OneForAll = Skill.OneForAll
--other skills in same format
}

When you need the variable, simply do:
local quirk = quirks[qu.Value]

Oh, I see. will try it out. Thanks

Still didn’t work, but will keep trying. Would a remote event somewhere work maybe?

Could work, just send the quirk u need to change as a variable.

This is what worked. Finally!

local RunService = game:GetService("RunService")
RunService.RenderStepped:Connect(function()
    if qu.Value == "stat1" then
        Skill.stat1.Visible = true
    else 
        Skill.stat1.Visible = false

    end
-- Etc