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

My Fireball giver script won't work. Why?

Asked by 9 years ago
1function onKeyDown(key)
2    Key = key:lower()
3    if key == "q" then
4        Move1 = game.Lighting.Fireball:Clone()
5        Move1.Parent  =  Backpack -- Would I have to change to game.Players.Backpack?
6    end
7    mouse.KeyDown:connect(onKeyDown)

Please correct it.

0
Is BackPack already defined? woodengop 1134 — 9y
0
What do you mean? kingstephen23 35 — 9y

1 answer

Log in to vote
0
Answered by
saenae 318 Moderation Voter
9 years ago

First off; you're definitely missing an end in that function, which in and of itself might be your only problem. Another reason the script isn't working might be that your Backpack and mouse aren't defined. To do so, use;

1Player = game.Players.LocalPlayer --Assuming this is a LocalScript
2mouse = Player:GetMouse()
3Backpack = Player.Backpack

Lastly, KeyDown is deprecated, and it would be in your best interest to use 'UserInputService'. In your example, you could use the following code;

01Player = game.Players.LocalPlayer
02mouse = Player:GetMouse()
03Backpack = Player.Backpack
04 
05serv = game:GetService("UserInputService")
06serv.InputBegan(function(input) -- triggers every time the client uses keyboard/whatever is available
07    if input.UserInputType == Enum.UserInputType.Keyboard and --Checks if client has a keyboard
08    input.UserInputState == Enum.UserInputState.Begin then -- Self-explanatory
09        if input.KeyCode == Enum.Keycode.Q then -- In keydown, this'd be 'if key == "q" then'
10            Move1 = game.Lighting.Fireball:Clone()
11                Move1.Parent = Backpack
12        end
13    end
14end)
0
Thanks so much I will use this one. kingstephen23 35 — 9y
Ad

Answer this question