Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My Fireball giver script won't work. Why?

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.

2 comments

0

Is BackPack already defined?

0

What do you mean?

1 answer

✓ Accepted answer

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)

1 comment

0

Thanks so much I will use this one.

This discussion is preserved as it was. New answers, comments, and votes are closed.