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

How do Touch function and KeyDown work together?

Asked by 6 years ago

I'm not sure if i'm doing correctly but I made lots of errors here, I would need help on how to fix this for my game.

script.Parent.Touched:connect(function()
    script.Parent.BillboardGui.Enabled = true
Mouse.KeyDown:connect(function(key)
 if (key == "e") then
    script.Parent.BillboardGui.TextBox.Text = "Here's help."
    wait(5)
    script.Parent.BillboardGui.TextBox.Text = "Press |E| for help"
end
end)
while
script.Parent.TouchEnded:connect(function()
    script.Parent.BillboardGui.Enabled = false
end
end)


I can't make it work somehow.

0
Rn from line 3, I am hearing, If u click the mouse then if the mouse clicked is e then so and so, so exactly idk whats happening around line 3 greatneil80 2647 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Getting user input from the mouse is deprecated, like I said for the millionth time. Instead, use UserInputService. For anyone saying that wait() is not deprecated, yes it is. It is crossed out.

script.Parent.Touched:Connect(function() --:connect is deprecated, use :Connect
    script.Parent.BillboardGui.Enabled = true
    game:GetService('UserInputService').InputBegan:Connect(function(key)
        if key.KeyCode == Enum.KeyCode.E then
            script.Parent.BillboardGui.TextBox.Text = "Here's help."
        Wait(5) --wait() is deprecated, use Wait()
            script.Parent.BillboardGui.TextBox.Text = "Press |E| for help"
    end)
end)

Also, do not use loops to listen for events. Just, just unnecessary.

script.Parent.TouchEnded:connect(function()
script.Parent.BillboardGui.Enabled = false
end

Also, do NOT use space to indent. Tab is quicker.

0
first of all in your second code YOU indented wrong and :connect is not depreacted :Connect is.. outlook1234567890 115 — 6y
0
:connect works fine so does :Connect.. outlook1234567890 115 — 6y
0
Thanks for advice on UserInputService, however, this does not solve my problem yet. NexoKami 12 — 6y
0
Whoops. The reason I indented wrong is because I used TNTsquad's code as a template and he indented wrong and I didn't catch it. Also, what is still your problem? hiimgoodpack 2009 — 6y
0
Also, :connect is deprecated, that why it is crossed out. http://wiki.roblox.com/index.php?title=RBXScriptSignal#connect_2 hiimgoodpack 2009 — 6y
Ad

Answer this question