I made a fireball script that when you equip it, you can press q to throw it. The only problem is that you can do it while it is unequipped also. I tried making an if statement for checking if it is equipped first, but it did nothing. I then tried a while loop but it crashes the studio.
here is the code right now.
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local replicatedStorage = game:GetService("ReplicatedStorage")
local fireAnim = replicatedStorage.FireballAnimation
local debounce = false
local equipped = false
script.Parent.Equipped:Connect(function()
equipped = true
if equipped == true do -- check if it is equipped
UserInputService.InputBegan:Connect(function(Input , IsTyping)
if not IsTyping then
if not debounce then
debounce = true
if Input.KeyCode == Enum.KeyCode.Q then
game.ReplicatedStorage.Fireball:FireServer(fireAnim)
wait(1.5)
end
wait(0.1)
debounce = false
end
end
end)
end
end)
script.Parent.Unequipped:Connect(function()
print("Unequipped")
equipped = false -- make it unequipped
end)
any help?

1 comment
the while loop probably crashed because you didnt put a wait()