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

Trying to get keypress for a billboard GUI, not working, no errors in log?

Asked by 2 years ago
Edited 2 years ago

Hello! I am making a start interaction GUI for a rempy-styled chat system.

Here's the script.

This script is a Local script inside of a Dummy's lower torso

The selection is a frame similar to what the background frame is but a different color and invisible and it grows in size to give some feedback when you press the key.

local userinput = game:GetService("UserInputService")
local tweenservice = game:GetService("TweenService")

local TweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0, false, 0)

local tween1 = tweenservice:Create(script.Parent.selection.Size, TweenInfo, {UDim2.new(0, 200, 0, 60)})
local tween2 = tweenservice:Create(script.Parent.selection, TweenInfo, {UDim2.new(0, 1, 0, 60)})


local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.KeyDown:Connect(function(key)
    if key:lower() == "f" or key:upper() == "F" then
        script.Parent.selection.Visible = true
        print("yep")
        tween1:Play()
    end
end)


Image of the setup and Logs:

https://imgur.com/BlAUhdi

Things I've tried

I've used the Keydown method prior to this but while I was searching for a solution myself on the Roblox developer forum I was recommended to use this way to get key pressed.

The errors you do see in the output are all unrelated to it and are other scripts I've imported from another one of my games which I am not working in right now since it is laggy, so the other scripts dont work quite yet as I need to finish this text GUI before I can implement them into the GUI,

Any help is welcome and appreciated, thank you.

Edit: While trouble shooting this again I realised I was changing the size in the tween incorrectly, changed it to the correct way, problem still remains.

1 answer

Log in to vote
0
Answered by
boredlake 256 Moderation Voter
2 years ago
Edited 2 years ago

Edit: the error is actually because your LocalScript is not inside a valid object.

A LocalScript will only run Lua code if it is a descendant of one of the following objects:

A Player's Backpack, such as a child of a Tool A Player's character model A Player's PlayerGui A Player's PlayerScripts. The ReplicatedFirst service

You can find this information here.

The propertyTable of a tween requires a property being set to a value. As an example, for your case it would be {Size = UDim2.new(0, 200, 0, 60)}

Another thing is, on line 6 when you were defining your tween, you need to use script.Parent.selection as your Instance, since script.Parent.selection.Size is a property, not an instance.

Also, thank you for including a good explanation of the problem.

**NOTE: I recommend using UserInputService as that has superceded Mouse. I see that you have defined userinput at the top, so rather than,

mouse.KeyDown:Connect(function(key)
    if key:lower() == "f" or key:upper() == "F" then

at line 13, you should try

userinput.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.F then

This link might help a little more. Not quite sure how you didn't find it (if you didn't), but give it a try.

0
Hello, Thank you for your response and it works! and for user input service I initially thought that was the issue so I was searching forms to fix a problem that didn't exist, Thank you for helping me with this. asmetics 26 — 2y
Ad

Answer this question