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

Trying to make a script that is fired when a certain key is pressed. Can anyone help?

Asked by 5 years ago

So uh, I've been trying to make this script work for some time now with the UserInputService yet I still can't manage to find the solution. I am fairly new to this, so help would be appreciated.


local Player = game.Players.LocalPlayer local anim1 = Instance.new("Animation") anim1.AnimationId = "http://roblox.com/Assets?ID=2294643345" UIS = game:GetService("UserInputService") UIS.InputBegan:connect(function(key) if key.KeyCode == Enum.KeyCode.Q then print("Pressed!") local Fire1 = Instance.new("Fire", Player.Character.LeftHand) Fire1.Color = Color3.new(236, 139, 70) Fire1.SecondaryColor = Color3.new(255, 0, 0) Fire1.Heat = -20 Fire1.Size = 4 local Fire2 = Instance.new("Fire", Player.Character.RightHand) Fire2.Color = Color3.new(236, 139, 70) Fire2.SecondaryColor = Color3.new(255, 0, 0) Fire2.Heat = -20 Fire2.Size = 4 local animation1 = Player.Character.Humanoid:LoadAnimation(anim1) animation1:Play() wait(3) Fire1:destroy() Fire2:destroy() end end)

I am pretty sure the script doesn't go past the

function onKeyPress(inputObject, gameprocessed)
    if inputObject.KeyCode == Enum.KeyCode.Q then

part.

Thank you.

0
Is it a localscript? and where is the script located aazkao 787 — 5y
0
It is a localscript, and it's just located in workspace. iAduriteX 34 — 5y
0
then it wont work, put the local script in starterplayer scripts aazkao 787 — 5y

2 answers

Log in to vote
0
Answered by
aazkao 787 Moderation Voter
5 years ago

Not sure if you read my comment already, but as i said, putting a localscript in workspace wont work, you have to put it in starterplayerscripts, i just tried it and it printed out "pressed" so its working

0
Ohh that’s why... Thank you very much! iAduriteX 34 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

This is what I use in my games.

game:GetService("UserInputService").InputBegan:Connect(function(input,event)
    if input.KeyCode == Enum.KeyCode.Q then
        -- [code]
    end
end)

Make sure you use this in a local script!

0
It still doesn't seem to detect that I pressed the key. iAduriteX 34 — 5y

Answer this question