Weird LookVector moment

I have a giant eyeball. I want the giant eyeball to shoot the closest player to it (which it does) and I want the beam to explode when it touches something.

The issue is the explosion isn’t where the beam explodes, instead, it is near the origin.

I’ve looked on the Developer Hub and talked to people outside of Roblox but still got no help.

mapScripts["Turret Evasion"] = function(map, players)
	
	local turret = map.Turret
	local tweenService = game:GetService("TweenService")
	
	spawn(function()
		while true do
			wait(0.5)
			turret.BodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
			local rootParts = {}
			for index, player in pairs(players) do
				if player.Character ~= nil and player.Character:FindFirstChild("HumanoidRootPart") then
					rootParts[player.Name] = (turret.Position - player.Character:FindFirstChild("HumanoidRootPart").Position).magnitude
				end
			end
			
			local function getMin(dictionary)
				local lowestval = math.huge
				local lowestvalindex = 0
				for i, v in pairs(dictionary) do
					if lowestval > v then
						lowestval = v
						lowestvalindex = i
					end
				end
				return lowestvalindex, lowestval
			end
			
			local plr, minDistance = getMin(rootParts)
			if game:GetService("Players"):FindFirstChild(plr) ~= nil then plr = game:GetService("Players")[plr] end
			turret.BodyGyro.CFrame = CFrame.new(turret.Position, plr.Character:WaitForChild("HumanoidRootPart").Position)
		end
	end)
	
	while true do
		wait(math.random(0, 2))
		if map.Parent == workspace then
			
			local newBullet = turret.Parent.Bullet:Clone()
			newBullet.Parent = workspace
			local newBG = Instance.new("BodyGyro")
			newBG.Parent = newBullet
			newBG.CFrame = turret.CFrame
			newBG.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
			game:GetService("Debris"):AddItem(newBullet, 5)
			local newTween = tweenService:Create(
				newBullet,
				TweenInfo.new(0.5, Enum.EasingStyle.Circular, Enum.EasingDirection.Out, 0, true),
				{Size = Vector3.new(4, 4, 8)}
			)
			newTween:Play()
			local newBV = Instance.new("BodyVelocity")
			newBV.Parent = newBullet
			newBV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
			newBV.Velocity = newBullet.CFrame.LookVector * 94
			newBullet.Fire.Enabled = true
			newBullet.Touched:Connect(function(obj)
				if obj.CanCollide == true and obj ~= turret then
					local fire = turret.Parent.Fire:Clone()
					fire.Parent = workspace
					fire.Position = newBullet.CFrame.LookVector * (newBullet.Size.Z / 2)
					fire.Fire.Enabled = true
					game:GetService("Debris"):AddItem(fire, 5)
					local explosion = Instance.new("Explosion")
					explosion.Parent = workspace
					explosion.Position = newBullet.CFrame.LookVector * (newBullet.Size.Z / 2)
					explosion.BlastRadius = 16
					explosion.BlastPressure = 0
					game:GetService("Debris"):AddItem(explosion, 3)
					newBullet:Destroy()
				end
			end)
		end
	end
end

All help appreciated, thanks!

Add newBullet.Position to the Positions, perhaps.

I think it should be

fire.Position = newBullet.Position + newBullet.CFrame.LookVector * (newBullet.Size.Z / 2)

and

explosion.Position = newBullet.Position + newBullet.CFrame.LookVector * (newBullet.Size.Z / 2)

EDIT: Oh that’s exactly what @MysteriousVagabond said. My bad.

2 Likes