Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Two buttons are trying to deactivate each other?!

Asked by 4 years ago
Edited 4 years ago

So here's the code...

repeat wait() until script.Parent.Parent:IsA("ImageButton")
local button = script.Parent.Parent
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local mouse = player:GetMouse()
local children = script.Parent.Parent.Parent:GetChildren()
local enabled = script.Enabled
local yes = true
local u = game:GetService("UserInputService")
spawn(function()
    while true do
        wait()
        if enabled.Value == true then
            yes = true
            button.ImageColor3 = Color3.fromRGB(189, 189, 189)      
            for i = 1, #children do
                if yes == true then
                    if children[i]:IsA("ImageButton") then
                        local spellbutton = children[i]
                        if spellbutton.Name == button.Name then return end
                        if spellbutton:FindFirstChildOfClass("Configuration") then
                            local spell = children[i]:FindFirstChildOfClass("Configuration")
                            if spell:FindFirstChild("Client") then
                                local clientscript = spell:FindFirstChild("Client")
                                clientscript.Enabled.Value = false
                            end
                        end
                    end
                end
            end
        else
            yes = false
            button.ImageColor3 = Color3.fromRGB(255, 255, 255)
        end
    end
end)
u.InputBegan:Connect(function(key, typing)
    if typing then return end
    if key.KeyCode == Enum.KeyCode[script.Letter.Value] then
        if enabled.Value == false then
            enabled.Value = true
        else
            enabled.Value = false
        end
    end
end)

When I activate both of the buttons, they will fight and then the user's inventory is forever stuck! Is there something wrong with my code? Too deep? Well here's a simple explanation.. Do you know Elemental Battlegrounds where you select a button and some of the previous spells you selected gets deactivated? Well I am trying to do it too, but instead, the two buttons fight together trying to deactivated one of the bool values but the other one is refusing (vice-versa)

Answer this question