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

I am having issues with keyboard inputs in my UI?

Asked by 6 years ago

Hello,i made this UI where when you press 'D' you first of all go from 'Equipment ' to 'Item' and then when you press D again it goes to 'Skills' (Image Linked)

and when you press A it goes from 'Skills' back to 'Item' and if you press A again to 'Equipment'

(The way it switches over is by making the Orange part which is an ImageLabel Visible and invisible (Equip, Items and skills have this ImageLabel which is called Hover))

how the UI looks: https://imgur.com/a/C3KxgxY

My problem is when i press 'D' it moves to items and then after instantly without any input it goes to skills

Im sorry if i missed anything and you are confused just comment ill reply and edit the post

The Script:

Mouse.KeyDown:connect(function(key)
    if key == 'd' and WSM.Value == 1 and hftweened == false then

        if Item_Equip_Skill == 0 then
                sound2:Play()
                wait(0.1)
                holdframe:TweenPosition(UDim2.new(0,0,0,0),'Out' ,'Sine',  0.5 )
                wait(0.5)
                hftweened = true
                EquipHover.Visible = true
                ItemHover.Visible = false
                SkillHover.Visible = false
                wait(0.2)
                Item_Equip_Skill = 1

        end

        if Item_Equip_Skill == 1 then
            EquipHover.Visible = false
            ItemHover.Visible = true
            SkillHover.Visible = false
            wait(0.2)
            Item_Equip_Skill = 2
            print(Item_Equip_Skill)
        end

        if Item_Equip_Skill == 2 then
            EquipHover.Visible = false
            ItemHover.Visible = false
            SkillHover.Visible = true
            wait(0.2)
            Item_Equip_Skill = 3
            print(Item_Equip_Skill)
        end

    end
end)
0
KeyDown is deprecated switch to UserInputService User#19524 175 — 6y

3 answers

Log in to vote
1
Answered by 6 years ago

You should use UserInputService as KeyDown is deprecated. Also use elseif instead of ending all those if's.

-- local script

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.D and WSM.Value == 1 and hftweened == false then

        if Item_Equip_Skill == 0 then
                sound2:Play()
                wait(0.1)
                holdframe:TweenPosition(UDim2.new(0,0,0,0),'Out' ,'Sine',  0.5 )
                wait(0.5)
                hftweened = true
                EquipHover.Visible = true
                ItemHover.Visible = false
                SkillHover.Visible = false
                wait(0.2)
                Item_Equip_Skill = 1


        elseif Item_Equip_Skill == 1 then
            EquipHover.Visible = false
            ItemHover.Visible = true
            SkillHover.Visible = false
            wait(0.2)
            Item_Equip_Skill = 2
            print(Item_Equip_Skill)

        elseif Item_Equip_Skill == 2 then
            EquipHover.Visible = false
            ItemHover.Visible = false
            SkillHover.Visible = true
            wait(0.2)
            Item_Equip_Skill = 3
            print(Item_Equip_Skill)
        end

    end
end)

I am not quite sure will this work. But I hope it will...

0
This looks promising. User#19524 175 — 6y
0
sadly it doesn't work, it fixes that it doesn't automatically go right but i also can't go right i'm just stuck at the beggining i tried changing a few things about this script i just cant find out what i am doing wrong, Thanks for the help though TigerClaws454 48 — 6y
0
You needd to change other scripts to be like this in order to work cuz this script works only for Key D AswormeDorijan111 531 — 6y
Ad
Log in to vote
1
Answered by 6 years ago

I found out what i did wrong i put 'if hftweened == true' in the first if and hftweened becomes false in that script itself.

thanks for the help anyway

i made some changes and fixed it my script now looks like this if you're interested :

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.D and WSM.Value == 1 and hftweened == false then

                sound2:Play()
                wait(0.1)
                holdframe:TweenPosition(UDim2.new(0,0,0,0),'Out' ,'Sine',  0.5 )
                wait(0.5)
                hftweened = true
    end

if input.KeyCode == Enum.KeyCode.D and WSM.Value == 1 and hftweened == true then
    if Item_Equip_Skill == 0 then
        EquipHover.Visible = true
        ItemHover.Visible = false
        SkillHover.Visible = false
        Item_Equip_Skill = 1

    elseif Item_Equip_Skill == 1 then
        EquipHover.Visible = false
        ItemHover.Visible = true
        SkillHover.Visible = false

        Item_Equip_Skill = 2

    elseif  Item_Equip_Skill == 2 then
        EquipHover.Visible = false
        ItemHover.Visible = false
        SkillHover.Visible = true

        Item_Equip_Skill = 3
    end
end
end)
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Edit for AswormeDorijan111 answer:

-- local script

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input, gpe)
    if gpe then return end 

    if input.KeyCode == Enum.KeyCode.D then
        if WSM.Value == 1 and hftweened == false then
            if Item_Equip_Skill == 0 then
                sound2:Play()
                wait(0.1)

                holdframe:TweenPosition(
                    UDim2.new(0,0,0,0),
                    Enum.EasingDirection.Out ,
                    Enum.EasingStyle.Sine,
                    0.5 
                )

                wait(0.5)

                hftweened = true
                EquipHover.Visible = true
                ItemHover.Visible = false
                SkillHover.Visible = false
                wait(0.2)

                Item_Equip_Skill = 1
            elseif Item_Equip_Skill == 1 then
                EquipHover.Visible = false
                ItemHover.Visible = true
                SkillHover.Visible = false
                wait(0.2)

                Item_Equip_Skill = 2
                print(Item_Equip_Skill)

            elseif Item_Equip_Skill == 2 then
                EquipHover.Visible = false
                ItemHover.Visible = false
                SkillHover.Visible = true
                wait(0.2)

                Item_Equip_Skill = 3
                print(Item_Equip_Skill)
            end
        end
    end
end)

If this worked remember to accept AswormeDorijan111's answer.

0
Ty <3 AswormeDorijan111 531 — 6y

Answer this question