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

How would I make an explosion wherever the beam hits?

Essentially, I want an explosion named "explosion" in the script which is a neon ball to have the position where the laser hits, so when it hits the spot it hits explodes My issue is that I tried to use the same beam position and the flaw is it will basically spawn in random place across a baseplate when it's launched. I need the ball to explode where the beam hits. Here's the code, thanks for the help.

local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
 
tool.Equipped:connect(function(mouse)
	print("Tool equipped!")
 
	mouse.Button1Down:connect(function()
		print("Mouse pressed!")
		local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300)
		local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
 
		local beam = Instance.new("Part", workspace)
		beam.BrickColor = BrickColor.Yellow()
		beam.FormFactor = "Custom"
		beam.Material = "Neon"
		beam.Transparency = 0.25
		beam.Anchored = true
		beam.Locked = true
		beam.CanCollide = false
		
		
 
		local distance = (tool.Handle.CFrame.p - position).magnitude
		beam.Size = Vector3.new(.5, .5, distance)
		beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
	    local explosion = Instance.new("Part", workspace)
		explosion.Shape = "Ball"
		explosion.BrickColor = BrickColor.Yellow()
		explosion.Transparency = 0.25
		explosion.Size = Vector3.new(25,25,25)
		explosion.Position = Vector3.new(.5, .5, distance)
		explosion.Anchored = true
		explosion.CanCollide = false
		explosion.Material = "Neon"
		local ex = Instance.new("Explosion")
		ex.Parent = explosion
		ex.Position = Vector3.new(10,10,10)
		explosion.Name = "explosion"
		
 
		game:GetService("Debris"):AddItem(beam, .7)
 
		if part then
			local humanoid = part.Parent:FindFirstChild("Humanoid")
 
			if not humanoid then
				humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
			end
 
			if humanoid then
				humanoid:TakeDamage(30)
			end
			script.Parent.Reload.Disabled = false
		    script.Disabled = true
			
		end
	end)
end)
--script.Parent.Reload.Disabled = false
		--script.Disabled = true
		

1 comment

0

Hint: After line 43, since you've already got the part. ;)

1 answer

✓ Accepted answer

You could just do this for both the sphere and the explosion,

explosion.Position = Vector3.new(mouse.hit.X, mouse.hit.Y, mouse.hit.Z)

or

explosion.CFrame = CFrame.new(mouse.hit.p)

1 comment

0

Thank you!

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