Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make this script more efficient?

repeat wait() until game.Players.LocalPlayer
GUI = script.Parent.Parent
Player = game.Players.LocalPlayer
mouse = Player:GetMouse()
inuse = script.Parent
debounce = true

function keydown(key)
    key = key:lower()
    if key == "q" and debounce == true then
		debounce = false
			if inuse.Value == "No" then
                debounce = false
                GUI:TweenPosition(UDim2.new(0.5, -350, 0.5, -150), "Out", "Elastic")
                inuse.Value = "Yes"
			elseif inuse.Value == "Yes" then
                GUI:TweenPosition(UDim2.new(0, -1500, 0, 0), "Out", "Elastic")
                inuse.Value = "No"
            end
            debounce = true
    end
end

mouse.KeyDown:connect(keydown)

this is my current script.. Everything works.. Just need it to be a bit more.. efficient? Any way I can do this?

1 answer

I don't see much of anything that you could change that would make it more efficient, I will make one change though.

repeat wait() until game.Players.LocalPlayer
GUI = script.Parent.Parent
Player = game.Players.LocalPlayer
mouse = Player:GetMouse()
inuse = script.Parent
debounce = true

mouse.KeyDown:connect(function(key) -- Made connection line and function one line
    key = key:lower()
    if key == "q" and debounce == true then
        debounce = false
            if inuse.Value == "No" then
                debounce = false
                GUI:TweenPosition(UDim2.new(0.5, -350, 0.5, -150), "Out", "Elastic")
                inuse.Value = "Yes"
            elseif inuse.Value == "Yes" then
                GUI:TweenPosition(UDim2.new(0, -1500, 0, 0), "Out", "Elastic")
                inuse.Value = "No"
            end
            debounce = true
    end
end)

1 comment

0

Why would you put them into 1? I don't believe it helps at all?

This discussion is preserved as it was. New answers, comments, and votes are closed.