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

Smooth Tool selecting?

Asked by
Cuvette 246 Moderation Voter
8 years ago

So, I've made my own ToolBar Gui, where the player can select either a sword, hatchet or open their bag. The only problem is, when selecting a sword then say a hatchet, they have to press the hatchet button twice to select it. Is there anyway I could fix this code in each of the buttons to make the selection instant and in one press.

Because as you can see, the player can press the button again to deselect the tool and that seems to be the problem.

Thanks in advance.

local StarterGui = game:GetService('StarterGui')

StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

enabled = true;
sword = game.Players.LocalPlayer.Backpack["ClassicSword"]

script.Parent.MouseButton1Down:connect(function()
    if enabled == false then
        game.Players.LocalPlayer.Character.Humanoid:UnequipTools()
        script.Parent.Image = "rbxassetid://424870026"
        print("Deselected")
        wait(0.2)
        enabled = true;
    end
end)

script.Parent.MouseButton1Down:connect(function()
if enabled == true then
    game.Players.LocalPlayer.Character.Humanoid:EquipTool(sword)
    script.Parent.Image = "rbxassetid://424870066"
        if game.Players.LocalPlayer.leaderstats1.EquippedAxe.Value == 1 then
            script.Parent.Parent.AxeSlot.Image = "rbxassetid://423840627"
        end
        if game.Players.LocalPlayer.leaderstats1.EquippedAxe.Value == 100 then
            script.Parent.Parent.AxeSlot.Image = "rbxassetid://423907054"
        end
    print("Selected")
    wait(0.2)
    enabled = false;
    end
end)
2
Why are you using two functions? User#11440 120 — 8y
0
One is to check is the button is enabled and in-use and one is to check if it's disabled. And I just realised I could have put it in one Cuvette 246 — 8y
0
But this still hasn't solved the issue Cuvette 246 — 8y
0
it waits 0.2 seconds before making enabled false so if the player clicks really fast then they cant switch it the first time due to the debounce, try removing the wait or making it wait() with no numbers in it. This is the smallest amount of time roblox can delay. LifeInDevelopment 364 — 8y

Answer this question