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

Fireball not going in straight line and when released it is still damaging the creator?

It seems when you click the fireball it just stays in one spot and goes up, not stay up and go in the direction you clicked. Also, the touch event doesn't seem to stop the fireball from damaging the creator. Are there any problems? I am really clueless, I am currently just trying to build the basics of the fireball so I can eventually add it to a game, thus adding effects to it.

Local script

local tool =script.Parent
local player = tool.Parent.Parent
local event = tool.Event
local Mouse = player:GetMouse()
--local damage = --Future Thing

tool.Equipped:connect(function(equip)
	equip.Button1Down:connect(function(mouse)
		print("Clicked")
		local distance = (player.Character.Torso.Position - Mouse.Hit.p).Magnitude
		 if distance >= 5 then
		event:FireServer()
		print("Fired")
		game.Workspace:WaitForChild("FireBall").Touched:connect(function(hit)
			if hit~= nil and not hit.Parent:IsDescendantOf(tool.Parent.Parent) then
				local hum = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")
				if hum ~= nil then
					hum:TakeDamage(50)
				   end
				end
			end)
		end
	end)
end)

Server Script

local tool =script.Parent
local player = tool.Parent.Parent
local event = tool.Event
local Mouse = player:GetMouse()

event.OnServerEvent:connect(function()
	local part = Instance.new("Part")
	part.Parent = game.Workspace
	part.Name = "FireBall"
	part.Shape = "Ball"
	part.TopSurface = "Smooth"
	part.BottomSurface = "Smooth"
	part.BrickColor = BrickColor.new("Red")
	part.Size = Vector3.new(5,5,5)
	part.Transparency = 1
	part.CFrame = player.Character.Torso.CFrame +Vector3.new(0,0,-5)
	part.CanCollide = false
	
	--Add Affects
	local fire = Instance.new("Fire")
	fire.Name = "FIRE"
	fire.Parent = part
	fire.Size = 100
	
	local force = Instance.new("BodyVelocity")
	force.MaxForce = Vector3.new(50, 50, 50)
	force.Parent = part
	
	
	
	
	
	
end)

1 comment

0

The script is 100% fixed, try it out!(The fire ball moves to where you clicked. If it you click on the floor it will go through the floor). Read the edit in my answer.

1 answer

✓ Accepted answer

#What you could do?

  • Add a "Creator" tag to see who made the fireball. If it touches the person who is in the creator tab, make it ignore the player.
  • Use the bodyforce correctly to make it move where wanted.
  • Use the touched event inside the server script

#Creator Tag A Creator tag is an easy way to keep track who made the projectile, and who killed a player.

local creatortag = Instance.new("ObjectValue", part)
creatortag.Value = workspace.Player1 --The creator is player1

we can use this to prevent damage.

if p.Parent == creatortag.Value then
	return --end the code
end

#Bodyforce Firstly, in order to make the part float you need it's mass. Using :GetMass() to get the mass of the part and multiply it with the Gravity.

local bodyforce = Instance.new("BodyForce", part)
bodyforce.Force = Vector3.new(0,part:GetMass()*workspace.Gravity,0) --Unanchored part can float now.

We can use lookvector to change the body force so it shoots in a direction using CFrame.


#Touched event This should be in the ServerScript because by the looks of it, you're using FE. This is because LocalScripts are mainly used for coding on the client side. Not server sided. So think about it like an email. If you send an email to another player through the server, you'll obviously have to do it server sided. But if you're using a local script, then it's like your internet is down. You can't reach the server so you can't interact with the other users but you can still do everything on your computer that doesn't require internet. So if you were to use a LocalScript to make a part it would only be visible to the client, but will not send to the server and therefore will not send it to other players. You're the only person who can see the parts therefore you made a LocalPart.


#Final Product ###Local Script:

local tool =script.Parent
local player = tool.Parent.Parent
local event = tool.Event
local Mouse = player:GetMouse()
local damage = 10

tool.Equipped:connect(function(equip)
    equip.Button1Down:connect(function(mouse)
        print("Clicked")
        local distance = (player.Character.Torso.Position - Mouse.Hit.p).Magnitude
         if distance >= 5 then
        event:FireServer(damage,Mouse.Hit.lookVector)
        print("Fired")
        end
    end)
end)

###Server Script:

local tool =script.Parent
local event = tool.Event
local Basespeed = 50 --Edit to your liking(50 is pretty slow, I tested it.)

event.OnServerEvent:connect(function(plyr,dmg,lv)
    local part = Instance.new("Part")
    part.Parent = game.Workspace
    part.Name = "FireBall"
    part.Shape = "Ball"
    part.TopSurface = "Smooth"
    part.BottomSurface = "Smooth"
    part.BrickColor = BrickColor.new("Red")
    part.Size = Vector3.new(5,5,5)
    part.Transparency = 1
    part.CFrame = plyr.Character.Torso.CFrame:toWorldSpace(CFrame.new(0,0,-5))
    part.CanCollide = false
    --Oops! I realized you can just make the character a variable! Creator Tag unneeded.
    part.Touched:connect(function(p)
    if p.Parent ~= plyr.Character and p.Parent:FindFirstChild("Humanoid") then
        p.Parent.Humanoid:TakeDamage(dmg)
    end
    end)

    --Add Affects
    local fire = Instance.new("Fire")
    fire.Name = "FIRE"
    fire.Parent = part
    fire.Size = 100

    local force = Instance.new("BodyForce")
    force.Force = Vector3.new(1,1,1)*Basespeed*lv+Vector3.new(0,part:GetMass()*workspace.Gravity)
    force.Parent = part






end)


Hope it helps!


##Edit: Change the Basespeed inside of the server script, this will determine how fast it'll move in all directions in studs.

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