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

Can anyone help me with a problem in a fireball script?

I made a script that lets the player shoot multiple fireballs by pressing f. It worked, so then I want to delete the Fireballs from Workspace after being shot. This is what I have for now, it doesn't work. I also need help with this damaging script. After the bullets are shot it the script won't find them in Workspace.

Player = game.Players.LocalPlayer

Char = Player.Character

Torso = Char.Torso

Mouse = Player:GetMouse()

Attack = false

Mouse.KeyDown:connect(function(key)
	local key  = key:lower()
	if key == "f" and (not Attack) then
		Attack = true
	   for i = 0, 10, 1 do
	        local Ball = Instance.new("Part")
	        Ball.Name = "Bullets"
            Ball.Parent = game.Workspace
            Ball.Shape = "Ball"
            Ball.Size = Vector3.new(1,1,1)
            Ball.Transparency = .4
            Ball.TopSurface = "Smooth"
            Ball.BottomSurface = "Smooth"
            Ball.BrickColor = BrickColor.new("Really red")
            Ball.CFrame = Torso.CFrame * CFrame.new(0,0.5, -5)
            Ball.CanCollide = false
            local Fire = Instance.new("Fire")
            Fire.Parent = Ball
            local Bv = Instance.new("BodyVelocity")
            Bv.Parent = Ball
            Bv.maxForce = Vector3.new(math.huge,math.huge,math.huge)
            Bv.velocity = Torso.CFrame.lookVector * 100   
            wait(.05)
	   end
	   wait(3)
	   game.Workspace.Bullets:Destroy()
	   Attack = false
	end
end)

game.Workspace.Bullets.Touched:connect(function(part)
    local h = part.Parent:findFirstChild("Humanoid")
    if(h~=nil)then
       h.Health = h.Health - 5
    end
end)

2 comments

0

Your question's quite unclear. What's the problem?

0

It would be a lot easier to just add the new bullet to the game debris

2 answers

Quick tip on removing your bullets, use the "Debris" service.

Debris = game:GetService("Debris")
-- This is a static variable.

Debris:AddItem("Ball", 3)
-- INSERT this after line 32, then REMOVE line 36.

#DAMAGE

Creating an event outside of the function is a terrible way to have your bullets damage. For one thing, your bullets haven't fired yet, but you already set up an event listener on something that's nonexistent.

In lieu of this, set up a local function within the "for" loop.

Bv.velocity = Torso.CFrame.lookVector * 100 -- Line 32
--

local connection = Ball.Touched:connect(function(hit)
	local PlayerIsFound = game:GetPlayerFromCharacter(hit.Parent)
	if PlayerIsFound then
		local HumanoidIsFound = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid")
		if HumanoidIsFound then
			HumanoidIsFound:TakeDamage(10)
		end
	end
end)
--

wait(.05)

Your script is only destroying 1 bullet. Change: game.Workspace.Bullets:Destroy() to:

for _, v in pairs(game.Workspace:GetChildren()) do
if v.Name == "Bullets" then
	v:Destroy()
end
end

1 comment

0

Is there a way to fix the damage?

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