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

GUI Button That When Clicked, The Key "G" is Pressed? (UserInputService Problem)

Asked by 7 years ago
Edited 7 years ago

This was a continuation of my last question, but regardless, what the script is suppose to do is whenever this tool is Equipped, the GUI will be cloned, and from there, when the button is clicked, it will be equivalent to the G Key on the keyboard. Once it does that, it's suppose to do an animation. I have a link down at the end of these scripts.

I also have two other Local Scripts that are in relation to each other.

Here are the first two.

01local tool=script.Parent
02local gui=tool.PowerGui
03 
04tool.Equipped:connect(function()
05    tool.rMovement.Disabled=true
06    tool.lMovement.Disabled=true
07    local Player=game.Players:findFirstChild(tool.Parent.Name)
08    if Player and tool.Parent:findFirstChild("Humanoid") then
09        local c=gui:Clone()
10        c.Parent=Player.PlayerGui
11        c.Frame.Script.Disabled=false
12    end
13    if tool.HandValue.Value==1 then
14        tool.lMovement.Disabled=false
15    else tool.rMovement.Disabled=false
16    end
17end)

What this first script does is that it clones the first GUI, this GUI has no problems, it's working for me perfectly. (In this case it is called PowerGui)

I have a script that is powering this GUI. This is the script:

01local Player = script.Parent.Parent.Parent.Parent
02local ScreenGui = script.Parent.Parent
03local Frame = script.Parent
04 
05while true do
06    wait()
07    if Player:IsA("Player") then
08        if Player.Character:findFirstChild("ABL_Ball") then
09            Frame.Power.Text=Player.Character.ABL_Ball.PowerValue.Value
10            if Player.Character.ABL_Ball.HandValue.Value==0 then
11                Frame.Hand.Text="R"
12            else Frame.Hand.Text="L"
13            end
14        else break
15        end
16    else break
17    end
18end
19ScreenGui:Destroy()

So, what this does, it's a basketball, and there is a PowerValue, and a HandValue. This ball, whenever it is released, has a certain power people can use it on. The HandValue, is whatever the basketball is being dribbled. This basically occurs whenever a key on the keyboard is pressed. In this case, H/L. As you can see, at the very end, it destroys the GUI. This happens whenever the tool is unequipped, or it is being released.

My problem here are these two scripts.

01local tool=script.Parent
02local gui=tool.ControlsGui
03 
04tool.Equipped:connect(function()
05    tool.rMovement.Disabled=true
06    tool.lMovement.Disabled=true
07    local Player=game.Players:findFirstChild(tool.Parent.Name)
08    if Player and tool.Parent:findFirstChild("Humanoid") then
09        local c=gui:Clone()
10        c.Parent=Player.PlayerGui
11        c.TextButton.LocalScript.Disabled=false
12    end
13    if tool.HandValue.Value==1 then
14        tool.lMovement.Disabled=false
15    else tool.rMovement.Disabled=false
16    end
17end)

This is equivalent to the very first one, in fact, I'm pretty sure it works, but I want it to be perfect according to this script below:

01local tool =  script.Parent.Parent.Parent
02local gui = script.Parent.Parent
03local uis = game:GetService("UserInputService")
04local button = script.Parent
05 
06tool.Equipped:connect(function() uis.InputBegan:connect(function(input) --code end) end)
07    function Click()
08        if input.UserInputType == Enum.KeyCode.G then
09            local keyPressed = input.KeyCode
10        end
11    end
12end)
13 
14tool.Unequipped:connect(function() gui.Visible = false end)
15 
16script.Parent.MouseButton1Click:connect(Click)
17 
18end)

I've tried and tried, I feel like I'm missing something, but I don't know what it is. This basically is inside the GUI. Whenever the tool is equipped, I am able to do a function or a certain type of code. When the button is clicked, it's equivalent to pressing the "G" key on the keyboard.

I've really tried very hard to figure out my mistakes, but there's so much I still need to learn in order to become the very best scripter I can possibly be.

Here's the Link for visual reference: Link to Visual Reference

Thank you, if you actually read through or at least skimmed, thank you (: If you can help I will give an upvote and will accept any answers given (just have it be thorough enough for me to understand as a beginning scripter lol)

Thanks, LukeGabrieI aka EnergyBrickz

A script would be helpful! c:

It gave me errors like,

"Passed value is not a function" (Looked it up. it has to do with the Click Function I tried to incorporate.)

0
To explain the error you encountered: In your last quoted script, thanks to the partially commented out line 6, the Click function is thus inside a function that isn't run until after line 16 (and only after InputBegan occurs). Thus, on line 16, `Click` is still 'nil'. chess123mate 5873 — 7y

1 answer

Log in to vote
2
Answered by 7 years ago

Not exactly sure what you tried doing but here's a set up I would use. The function Start() will be called when they press the gui or click G while holding the tool. Put what you wish to execute in the function.

01local tool =  script.Parent.Parent.Parent
02local gui = script.Parent.Parent
03local button = script.Parent
04local Debounce = true
05local Active = false
06 
07local CoolDown = 1 -- Change to what you want
08local function Start()
09    -- Start animation and do whatever
10end
11 
12tool.Equipped:Connect(function()
13    Active = true
14  gui.Visible = false
15end)
View all 43 lines...
0
Sorry for weird spacing idk why it showed up like that on here iamnoamesa 674 — 7y
Ad

Answer this question