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

I am having issues with keyboard inputs in my UI?

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)

1 comment

0

KeyDown is deprecated switch to UserInputService

3 answers

✓ Accepted answer

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...

3 comments

0

This looks promising.

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

0

You needd to change other scripts to be like this in order to work cuz this script works only for Key D

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)

###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.

1 comment

0

Ty <3

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