I would want the projectile to constantly shoot out by itself as long as the player hold the hotkey but I do not know how to script that.
I do know how to make it rapid-fire but the only thing i don't know is the holding down key function.Any help?
The script that enables the projectile:
--// Services \\--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
--// Varaibles \\--
local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local Remote = ReplicatedStorage.FireBallEvent
local Mouse = plr:GetMouse()
--// Settings \\--
local Debounce = true
local Key = 'E'
UserInputService.InputBegan:Connect(function(Input, IsTyping)
if IsTyping then return end
local KeyPressed = Input.KeyCode
if KeyPressed == Enum.KeyCode[Key] and Debounce and Char then
Debounce = false
Remote:FireServer(Mouse.Hit)
wait(3)
Debounce = true
end
end)
The Set-up:
--// Services \\--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--// Variables \\--
local Remote = ReplicatedStorage.FireBallEvent
--// Settings \\--
local Damage = 10
Remote.OnServerEvent:Connect(function(plr, Mouse)
local Char = plr.Character or plr.CharacterAdded:Wait()
local Part = Instance.new('Part')
Part.Shape = Enum.PartType.Ball
Part.Anchored = false
Part.CanCollide = false
Part.Transparency = 0
Part.Color = Color3.fromRGB(255,176,0)
Part.Material = Enum.Material.Neon
Part.Size = Vector3.new(1,1,1)
Part.Name = 'FireBall'
Part.CFrame = Char.HumanoidRootPart.CFrame
Part.Parent = workspace
local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BodyVelocity.Velocity = Mouse.lookVector*30
BodyVelocity.Parent = Part
local Debounce = true
Part.Touched:Connect(function(h)
if h.Parent:FindFirstChild('Humanoid') and h.Parent.Name ~= plr.Name and Debounce then
Debounce = false
local Enemy = h.Parent.Humanoid
Enemy:TakeDamage(Damage)
Part:Destroy()
wait(1)
Debounce = true
end
end)
end)
I already added a RemoteEvent in ReplicatedStorage.

5 comments
a while loop for KeyDown should work
Thanks,I'll try that
When I added that,it loops it forever
KeyDown is deprecated do not use it new work
So what should I do?