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

Why won't localscript run a keyboard input function?

Asked by 9 years ago

I've been trying to get this to work, but seems that in online mode it won't function. Here is the code:

display = script.Parent
-- The variable above refers to the display where slides are shown!

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

colorSwap = display.Parent.SwapColors.Colors

usableSlides = {display.SelectNew, display.Beginner, display.TestFrame2}
-- The slides above are allowed to be used for anyone!

function move(to, from, hidden) -- Move the slides up, or right in the list of usuable ones!
    if hidden ~= nil then
        display.HiddenSlide.Value = hidden
    end

    if to ~= nil and from ~= nil then
        colorSwap.Value = to.Color.Value
        to.ZIndex = 2
        from.ZIndex = 1
        to:TweenPosition(UDim2.new(0, 3, 0, 3), "Out", "Bounce", 1.5) -- Move the one to the center!
        from:TweenPosition(UDim2.new(0, 3, 1.5, 3), "Out", "Bounce", 1.5) -- Move this one out of the frame!
    end
end

function selectSlide(direction) -- Here direction refers to the way the slides shall go. True means up, or right in the list, while False means the opposite.
    slideTo = nil -- Slide that needs to be shown.
    slideFrom = nil -- Slide that needs to be removed.

    if display.LastSlide.Value ~= nil then
        direction = nil
        move(display.LastSlide.Value, display.HiddenSlide.Value)
        display.LastSlide.Value = nil
        display.HiddenSlide.Value = nil
    end

    if direction then
        for num, slide in pairs(usableSlides) do -- Cycle through slides and locate the current one!
            if slide.Position.Y.Scale == 0 then
                slideFrom = slide
                if num < #usableSlides then
                    slideTo = usableSlides[num+1]
                else
                    slideTo = usableSlides[1]
                end
            end
        end
    else if direction == false then
        for num, slide in pairs(usableSlides) do -- Cycle through slides and locate the current one!
            if slide.Position.Y.Scale == 0 then
                slideFrom = slide
                if num > 1 then
                    slideTo = usableSlides[num-1]
                else
                    slideTo = usableSlides[#usableSlides]
                end
            end
        end
    end
    end
    move(slideTo, slideFrom)
end

function help() -- This returns the help page and adds more stuff than defaultly, thus the new function!
    slideFrom = nil
    slideTo = display.Help

    for num, slide in pairs(usableSlides) do -- Cycle through slides and locate the current one!
        if slide.Position.Y.Scale == 0 then
            slideFrom = slide
            display.LastSlide.Value = slide
        end
    end

    move(slideTo, slideFrom, display.Help)
end

mouse.KeyDown:connect(function (Key) -- When a player hits a key this is activated!
    if Key:lower() == "q" then -- If 'q' is pressed then go UP!
        selectSlide(true)
    else if Key:lower() == "e" then -- If 'e' is pressed then do DOWN!
        selectSlide(false)
    else if Key:lower() == "h" then
        help()
    else

    end
    end
    end
end)

This is inside the PlayerGui where it says localscripts will still run, though in my game I try hitting the keys and they don't seem to run the code. Do you have any way to fix this or am I just missing something?

Answer this question