Hello, so, im trying to make a script where a player can press a button(gui button) and it will do a function. But i only want them to do the function when pressing the button if a certain value is equal to true. The problem is i can use this
if script.Parent.ImageButton.IfEquiped.Value == true then
player.PlayerGui.Slots.Frame[script.Parent.ImageButton.SlotOn.Value].PressToEquip.MouseButton1Click:Connect(function()
--do function
end)
end
I cant use that because the script runs as soon as the player joins the game, and when the player joins the game the value is false. The script only runs once to determine if its equal to false or not. For clarification the reason the value has to be equal to true is because the Click function wont work if its not. Ive tried countless solutions and they dont work.
I really think you should ask, on here about the main issue for why you need this setup, but just to answer this post, maybe you should check when the .Value is changed with an event.
script.Parent.ImageButton.IfEquiped.Changed:Connect(function()
if script.Parent.ImageButton.IfEquiped.Value == true then
player.PlayerGui.Slots.Frame[script.Parent.ImageButton.SlotOn.Value].PressToEquip.MouseButton1Click:Connect(function()
--do function
end)
end
end)
I need it this way becuase i have an ability slot system, and when they equip the ability to the slot the it changes the slot on value to the slot the changed it to. So as you can see when they press the value(the slots) button, it gets the ability. But when the ability is unequipped the Slot on value goes back to nil because its not on a slot. That’s why it can only work if its equipped, so the solution you gave me doesnt work
Sorry, I probably just don’t really understand the problem. From what I see, you can let the player click a button, then check the value of the equipped ability
If you really need it to be that way, then you could probably get what you’re hoping for by wrapping it in a loop, maybe something like while wait(1) do?
Honestly, I’d rather you find a way to make this differently, because while this may be a solution to your problem, it’s a horifically inefficient one.