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

Fireball while running goes diagonally down and how to make fireball damage?

so, I finally made a fireball that launched perfectly when I press the "e" key, but I do not know how to make it do damage when it hits other players. I tried doing it but it doesnt work, and whenever I walk or run while launching it, it launches diagonally down... I do not know why.. Can someone help me so that even when im running or walking, it launches straight infront of me? Can someone pls help me?

local Player = game.Players.LocalPlayer
local char = Player.Character or Player.CharacterAdded:Wait()
local head = char:WaitForChild("Head")

local x = Instance.new("Part")
	x.BrickColor = BrickColor.new("Maroon")
	x.Shape = "Ball"
	x.Material = "Neon"
	x.TopSurface = "Smooth"
	x.BottomSurface = "Smooth"
	x.Anchored = false
	x.CanCollide = false
    x.Transparency = 0.5
	x.Size = Vector3.new(3,3,3);

local y = Instance.new("Fire")
	y.Size = 15
	y.Heat = 5





game:GetService("UserInputService").InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.E then
        local cl = x:Clone()  
		local cly = y:Clone()
		local v = Instance.new("BodyVelocity")
				v.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
				v.Velocity = Player.Character.UpperTorso.CFrame.lookVector * 60
				v.Parent = cl
				cly.Parent = cl
        		cl.Parent = game.Workspace -- You forgot to Parent it
       			cl.Position = head.Position + (head.CFrame.lookVector * 5) 
				game.Debris:AddItem(cl, 4)
       										 -- Position of head + push it in the direction the 
       										 -- player is looking and * 2 away from the player
    end
end)

x.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 20
	end
end)

1 answer

I can only try to answer the fireball damage part.

Well, first, you did hit.Parent:FindFirstChild("Humanoid"), which is bad. Also, it says that you are looking if the actual part is touched, not the clone. To fix this (I think), you should try this:

local cl = x:Clone()
local cly = y:Clone() -- Move these out of the function so it would work

cl.Touched:connect(function(hit)
	if hit.Character.Humanoid then
		hit.Character.Humanoid.Health = hit.Character.Humanoid.Health - 20
	end
end)

If this doesn't work, I'm sorry, but I'm still a noob at scripting. And if it does, I would appreciate it if you press accept answer!

2 comments

0

It did not work.. but I did realize that the reason for my fireball going down was because of CanCollide, i put the CanCollide equals to false although it was supposed to be true.. haha. but I shall accept ur answer! TY

0

Thanks!

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