Issue on making boss attack

What am I trying to achieve?

I’m trying to make a boss that attacks and shoots a part at a player(is only a part as for now). I’m cloning a part from the replicated storage and putting it at the position of the boss. Then I am attempting to use vector force or linear velocity to move the part to a player’s position.

Issue?

I don’t know how I can make the part move to the player’s position. I’m also uncertain of how to use attachments and overall velocities.

What have I tried?

I’ve tried looking at the AI assistant, looking up tutorials, and majorly retrying my code but nothing has worked.

Main:

local rs = game:GetService("ReplicatedStorage")
local part = rs:WaitForChild("Egg")
local insanity = rs:WaitForChild("Insanity")

local bossattacks = rs:WaitForChild("BossAttacks")

local button = workspace.InteractionTable.Button

local lobby = workspace.Lobby
local base = lobby.Base


local debounce = false
game.ReplicatedStorage.BossEvent.OnServerEvent:Connect(function()
	local clonedegg = part:Clone()
	clonedegg.Parent = workspace
	clonedegg.Position = base.Position + Vector3.new(0,40,0)
	clonedegg.Transparency = 0
	clonedegg.Happy.Transparency = 0
	game.ReplicatedStorage.BossAlertEvent:FireAllClients()
end)


function looking()
	while task.wait() do
		local players = game:GetService("Players")
		local get = players:GetPlayers()
		local random = math.random(1,#get)
		local chosen = get[random]
		local HRP = chosen.Character.HumanoidRootPart
		workspace:WaitForChild("Egg").CFrame = CFrame.lookAt(workspace:WaitForChild("Egg").Position,HRP.Position)
		task.wait(5)
	end
end
game.ReplicatedStorage.PrepareEvent.OnServerEvent:Connect(function()
	local ts = game:GetService("TweenService")
	insanity.Parent = workspace
	local part = workspace:WaitForChild("Insanity")
	local info = TweenInfo.new(
		10,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	local prop = {
		Position = Vector3.new(1.48, 15, -2.194)
	}
	
	local tween = ts:Create(part,info,prop)
	tween:Play()
	repeat
		task.spawn(looking)
		local attackstable = {
			bossattacks.BombingRelationship,
			bossattacks.DevilGlob
		}
		local randomattack = math.random(1,#attackstable)
		local chosenattack = attackstable[randomattack]
		
		if chosenattack.Name == "DevilGlob" then
			print("DevilGlob happened")
			local players = game:GetService("Players")
			local get = players:GetPlayers()
			local random = math.random(1,#get)
			local chosen = get[random]
			local char = chosen.Character
			local HRP = char:WaitForChild("HumanoidRootPart")
			local attach = Instance.new("Attachment", HRP)
			
			local cloned = chosenattack:Clone()
			local velocity = Instance.new("VectorForce", cloned)
			cloned.Parent = workspace
			cloned.Position = workspace:WaitForChild("Egg").Position
			velocity.Force = Vector3.new(0,0,4000) + HRP.CFrame.LookVector.Unit * 1000
		elseif chosenattack.Name == "BombingRelationship" then
			print("Bombing happened")
			local cloned2 = chosenattack:Clone()
			cloned2.Parent = workspace
			cloned2:MoveTo(lobby.Base.Position + Vector3.new(math.random(-100,100),11.5,math.random(-100,100)))
			cloned2.ImpactPart.CanCollide = false
			for i = 1,50 do
				cloned2.TinyNuke:MoveTo(cloned2.TinyNuke.PrimaryPart.Position + Vector3.new(0,-0.375,0))
				task.wait()
			end
			local expanse = Instance.new("Part", workspace)
			expanse.Anchored = true
			expanse.Size = Vector3.new(6,6,6)
			expanse.Color = Color3.new(0.956008, 0.423392, 0.127703)
			expanse.Material = Enum.Material.Neon
			expanse.Shape = Enum.PartType.Ball
			expanse.Position = cloned2.TinyNuke.Tank.Position
			for i = 1,12,1 do
				expanse.Size = expanse.Size + Vector3.new(1,1,1)
				task.wait()
			end
			expanse.Touched:Connect(function(hit)
				if not debounce then
					if hit.Parent:FindFirstChild("Humanoid") then
						debounce = true
						hit.Parent.Humanoid:TakeDamage(75)
						task.wait(1)
						debounce = false
					end
				end
			end)
			expanse:Destroy()
			cloned2:Destroy()
		end
		task.wait(5)
	until workspace:WaitForChild("Egg").Health.Value == 0
end)

This is where the error is happening:

if chosenattack.Name == "DevilGlob" then
			print("DevilGlob happened")
			local players = game:GetService("Players")
			local get = players:GetPlayers()
			local random = math.random(1,#get)
			local chosen = get[random]
			local char = chosen.Character
			local HRP = char:WaitForChild("HumanoidRootPart")
			local attach = Instance.new("Attachment", HRP)
			
			local cloned = chosenattack:Clone()
			local velocity = Instance.new("VectorForce", cloned)
			cloned.Parent = workspace
			cloned.Position = workspace:WaitForChild("Egg").Position
			velocity.Force = Vector3.new(0,0,4000) + HRP.CFrame.LookVector.Unit * 1000
1 Like

My solution for this in my games is just making the force push the part towards it look vector always, and then set the CFrame to be looking at that direction

local player= --Target player
local origin=--where the projectile comes from

CFrame.new(origin.Position,player.PrimaryPart.Position)
1 Like

I actually fixed this and used AssemblyLinearVelocity so that I could use the look vector of a boss that’s shooting these projectiles. I’m sorry, I will add solution.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.