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

Connect MouseButton1Click with Specific Keys on Keyboard onto a GUI?

Asked by 7 years ago
Edited 7 years ago

This sounds really complicated, but basically, I'm creating a GUI inside a Tool that is basically cloned whenever the Tool is equipped, and inside this GUI I have a button, and what this button does is that whenever it is clicked on, a specific key on the keyboard is pressed. I am a really beginning scripter, and if you guys could fix my script up, it would be awesome!

local Player = script.Parent.Parent.Parent.Parent
local ScreenGui = script.Parent.Parent
local Tool=script.Parent.Parent.Parent
local keys={false,false}
local debris = game:service("Debris")

------------------------------------------------
local aroundRight="g" -- the key pressed
-------------------------------------------------

while true do
    wait()
    if Player:IsA("Player") then
        function AroundRight(key) --this is what happens to the tool (basically a basketball)
        if (key==aroundRight) then
        Tool.rMovement.Disabled=true
        Tool.lMovement.Disabled=true
        Tool.HandValue.Value = 1
            Tool.GripPos = Vector3.new(0.5, -0.5, -0.3)
            wait(0.01)
            Tool.GripPos = Vector3.new(0.5, -1, 0)
            wait(0.01)
            Tool.GripPos = Vector3.new(0.5, -1.5, 0.5)
            wait(0.01)
            Tool.GripPos = Vector3.new(0.5, -1.5, 1)
            wait(0.01)
            Tool.GripPos = Vector3.new(0.5, -1.5, 1.5)
            wait(0.01)
            Tool.GripPos = Vector3.new(0.5, -1, 2)
            wait(0.01)
            Tool.GripPos = Vector3.new(1, -0.5, 2.5)
            wait(0.01)
            Tool.GripPos = Vector3.new(1.5, 0, 3)
            wait(0.01)
            Tool.GripPos = Vector3.new(2, 0.5, 3)
            wait(0.01)
            Tool.GripPos = Vector3.new(2.5, 1, 3)
            wait(0.01)
            Tool.GripPos = Vector3.new(3, 1.5, 3)
            wait(0.01)
            Tool.GripPos = Vector3.new(2.5, 2, 2.5)
            wait(0.01)
            Tool.GripPos = Vector3.new(2, 2.5, 2)
            wait(0.01)
            Tool.GripPos = Vector3.new(1.5, 3, 1.5)
            wait(0.01)
            Tool.GripPos = Vector3.new(1, 3.5, 1)
            wait(0.01)
            Tool.GripPos = Vector3.new(0.5, 3, 0.5)
            wait(0.01)
            Tool.GripPos = Vector3.new(0.5, 2.5, 0)
            wait()
        Tool.lMovement.Disabled=false -- basically I have it where I can use the basketball on both my left hand and right hand.
        end
    else break
        end
    else break
    end
end
ScreenGui:Destroy() --i want it so that whenever the Tool is unequipped, it would remove the GUI

Tool.Equipped:connect(function()
 script.Parent.MouseButton1Click:connect(AroundRight) -- basically the function where when it clicks it connects the upper script.
end)

I don't know if I'm suppose to use UserInputService with it or not, or if there's an even simpler method like ContextActionService, but I don't know how to develop the script if I ever tried using those services, lol. (Yet alone even know how to create one.)

All in all, a button that whenever it is clicked on, a key on the keyboard will be equivalent to it, and once the ball is unequipped, the button will disappear. Also, if you could implement a debounce whenever the button is clicked on that would be wonderful! :)

Thanks, LukeGabriel aka EnergyBrickz

1 answer

Log in to vote
1
Answered by 7 years ago

I think i got it. The problem that i see was in the while loop. The code below while will be executed when its condiction is false. As your loop's condiction is directally set to true, the code will not be executed anyhow...

0
so what do i do gg LukeGabrieI 73 — 7y
0
omg 2 months later lul. So... you should put the loop in the end of the code arthurgps2 67 — 7y
Ad

Answer this question