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
function onKeyDown(key)
    Key = key:lower()
    if key == "q" then
        Move1 = game.Lighting.Fireball:Clone()
        Move1.Parent  =  Backpack -- Would I have to change to game.Players.Backpack?
    end
    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;

Player = game.Players.LocalPlayer --Assuming this is a LocalScript
mouse = Player:GetMouse()
Backpack = 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;

Player = game.Players.LocalPlayer
mouse = Player:GetMouse()
Backpack = Player.Backpack

serv = game:GetService("UserInputService")
serv.InputBegan(function(input) -- triggers every time the client uses keyboard/whatever is available
    if input.UserInputType == Enum.UserInputType.Keyboard and --Checks if client has a keyboard
    input.UserInputState == Enum.UserInputState.Begin then -- Self-explanatory
        if input.KeyCode == Enum.Keycode.Q then -- In keydown, this'd be 'if key == "q" then'
            Move1 = game.Lighting.Fireball:Clone()
                Move1.Parent = Backpack
        end
    end
end)
0
Thanks so much I will use this one. kingstephen23 35 — 9y
Ad

Answer this question