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

Making a cool down and exploding the Fireball when it hits something?

I'm making a power up, you shoot a "Fireball" out of the player and into the workspace. I want to see how I could make it so that when the "Fireball hits something it explodes, but after 60 seconds if the "Fireball" didn't hit anything it just is destroyed. And also on how to make a cool down. I've tried these things out but they didn't work.

Here's the script

local Plr = game.Players.LocalPlayer
local Mouse = Plr:GetMouse()
local Ammo = 1
Mouse.KeyDown:connect(function(key)
	key = key:lower()
	if key =="f" then
		print("F has been pressed!")
	
	local FireBall = Instance.new("Part")
	FireBall.Shape = "Ball"
	FireBall.BrickColor = BrickColor.new("Maroon")
	FireBall.Transparency = 0.5
	FireBall.TopSurface = "Smooth"
	FireBall.BottomSurface = "Smooth"
	local Fire = Instance.new("Fire")
	Fire.Parent = FireBall
	FireBall.CFrame = Plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-6)	
	local BodyVelocity = Instance.new("BodyVelocity")
	BodyVelocity.Velocity = Plr.Character.HumanoidRootPart.CFrame.LookVector * 90
	BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	BodyVelocity.Parent = FireBall
	local Explosion = Instance.new("Explosion")
	 FireBall.Parent = workspace
Ammo = Ammo - 1 
wait(3)
Ammo = 1 

wait(1)
FireBall:Destroy()

	end

end)

3 comments

0

Don't use key down it's depreciated user userinput service

0

and why are you getting your key press from the mouse

0

im following a tutorial from 2 years ago

1 answer

What I will do is create a touched event and destroy the fireball if it touches something (you can add your own code to deal with what to do with the hit in there) I will then add the fireball to the debris service so that it will only last for 60 seconds Afterwards it will wait for the fireball to be destroyed and then replenish the ammo variable.

I kept the cooldown of 3 seconds there.

local Plr = game.Players.LocalPlayer
local Mouse = Plr:GetMouse()
local Ammo = 1
Mouse.KeyDown:connect(function(key)
    key = key:lower()
    if key =="f" then
        print("F has been pressed!")

    local FireBall = Instance.new("Part")
    FireBall.Shape = "Ball"
    FireBall.BrickColor = BrickColor.new("Maroon")
    FireBall.Transparency = 0.5
    FireBall.TopSurface = "Smooth"
    FireBall.BottomSurface = "Smooth"
    local Fire = Instance.new("Fire")
    Fire.Parent = FireBall
    FireBall.CFrame = Plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-6)    
    local BodyVelocity = Instance.new("BodyVelocity")
    BodyVelocity.Velocity = Plr.Character.HumanoidRootPart.CFrame.LookVector * 90
    BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
    BodyVelocity.Parent = FireBall
    local Explosion = Instance.new("Explosion")
    --create touched event
    FireBall.Touched:Connect(function(hit)
        wait()
        FireBall:Destroy()
    end)
    FireBall.Parent = workspace
    --Add Fireball to debris (will be destroyed after 60 seconds)
    game:GetService("Debris"):AddItem(FireBall,60)

    Ammo = Ammo - 1 
    --wait for fireball to be destroyed
    while FireBall.Parent do
        wait()
    end
    
    --cooldown
    wait(3)
    Ammo = 1 

    end

end)

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