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

Why isnt my KeyDown Disappear script not working?

Asked by
smh97 0
6 years ago

It opens, but then it doesnt close..

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
gui = script.Parent
box = gui.ShopGUI
Open = false
-- enuff with my h0t neatness 0k

function PressR(key)
    if (key == "r") then
        if (Open == false) then
            box.Visible = true
        elseif (Open == true) then
            box.Visible = false
            Open = false
        end
    end
end

Mouse.KeyDown:connect(PressR)

2 answers

Log in to vote
0
Answered by 6 years ago

One reason I suspect is because the KeyDown method has been deprecated and is no longer supported in favour of UserInputServer & ContextActionService http://wiki.roblox.com/index.php?title=API:Class/UserInputService I would personally use these however I have written down your script with these changes implemented for you.

player = game.Players.LocalPlayer
gui = script.Parent
box = gui.ShopGUI
open = false
-- enuff with my h0t neatness 0k

game:GetService("UserInputService").InputBegan:Connect(function(input , gp)
    if input.KeyCode == Enum.KeyCode.R then
            if not open then
                    box.Visible = true
            open = true
            elseif open then
                    box.Visible = false
                    open = false
            end
        end
end)

Ad
Log in to vote
0
Answered by
oSyM8V3N 429 Moderation Voter
6 years ago

First, keyDown is HIGHLY deprecated, so its better off to use the UserInputService, i couldn't have time to review your script to see whats wrong, but i have an example of one with UIS shown here:

local UIS = game:GetService("UserInputService")
local p = game.Players.LocalPlayer
mouse = p:GetMouse()
local gui = script.Parent
local box = gui:WaitForChild("ShopGUI")
Opened = false
debounce = false

local function OpenAndClone(Input, gameProcessed)
local KeyCode = Input.KeyCode

if KeyCode == Enum.KeyCode.R and debounce == false then
box.Visible = true

elseif KeyCode == Enum.KeyCode.R and debounce == true then
box.Visible = false

end
end

UIS.InputBegan:Connect(OpenAndClone)

Any more questions, please feel free to ask, since i didn't have time to review it

--oSy

Answer this question