How do i make the entity rebound? (rooms fan-made)

i followed a tutorial from @GnomeCode

The void is an entity that was drawn by my little brother, looks like this
The_void-removebg-preview
the entire game is driven by a tutorial (i cant code it on my own, like what the heck is a hashtag before a number) and i dont know how to make him rebound 1-3 times

heres the code from the tutorial (its a modulescript):

local Void = {}
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

function Void.FindPlayers(model)
	local players = Players:GetPlayers()
	local characters = {}
	for i, player in ipairs(players) do
		if player.Character then
			table.insert(characters, player.Character)
			
		end
	end
	
	local overlapParams = OverlapParams.new()
	overlapParams.FilterType = Enum.RaycastFilterType.Whitelist
	overlapParams.FilterDescendantsInstances = characters
	local collisions = workspace:GetPartsInPart(model.Hitbox, overlapParams)
	
	for index, obj in ipairs(collisions) do
		if obj.Name == "HumanoidRootPart" then
			local rayDirection = obj.Position - model.Void.Position
			local result = workspace:Raycast(model.Void.Position, rayDirection)
			if result and result.Instance then
				local hit = result.Instance
				if hit == obj or hit:FindFirstAncestor(obj.Parent.Name) then
					print("HIT")
					obj.Parent.Humanoid.Health = 0
				end
			end
		end
	end
end

function Void.LerpTo(model, target)
	local alpha = 0
	local speed = 200
	local distance = (model.PrimaryPart.Position - target.Position).Magnitude
	local relativeSpeed = distance / speed
	local startCFrame = model.PrimaryPart.CFrame
	local loop = nil
	local reachedTarget = Instance.new("BindableEvent")
	
	loop = RunService.Heartbeat:Connect(function(delta)
		Void.FindPlayers(model)
		local goalCFrame = startCFrame:Lerp(target.CFrame, alpha)
		model:PivotTo(goalCFrame)
		alpha += delta / relativeSpeed
		if alpha >= 1 then
			loop:Disconnect()
			reachedTarget:Fire()
		end
	end)
	
	reachedTarget.Event:Wait()
	
end

function Void.Navigate(model, prevNum, maxNum, generatedRooms)
	for i=prevNum, maxNum do
		local room = generatedRooms[i]
		Void.LerpTo(model, room.Enterance)
		
		local waypoints = room:FindFirstChild("Waypoints")
		if waypoints then
			for i=1, #waypoints:GetChildren() do
				Void.LerpTo(model, waypoints[i])
			end
		end
		
		Void.LerpTo(model, room.Exit)
		
	end
end

function Void.new(number, generatedRooms)
	
	local enemyModel = workspace.Enemies.Void:Clone()
	
	local prevNum = number - 10
	local maxNum = number + 1
	local prevRoom = generatedRooms[prevNum]
	if not generatedRooms[maxNum] then
		maxNum = #generatedRooms
	end
	local maxRoom = generatedRooms[maxNum]
	
	enemyModel:PivotTo(prevRoom.Enterance.CFrame)
	enemyModel.Parent = workspace
	
	Void.Navigate(enemyModel, prevNum, maxNum, generatedRooms) 
	
	local lastDoor = maxRoom.Door
	lastDoor.OpenEvent:Fire()
	
	enemyModel.Void.Anchored = false
	enemyModel.Particles.Anchored = false
	enemyModel.Particles.Void.Enabled = false
	enemyModel.Void.CanCollide = false
	enemyModel.Particles.CanCollide = false
end

return Void

heres the explorer that handles room generation and entity spawning
image
smiler is a different entity that works fine, and im not using right now (you can see the modulescript above)

Server handles room generation, and spawns the void every % 12 == 0 rooms

any new information or any code or questions about this i will answer, if i can

The code of the void enemy kills the player?

1 Like

if its close enough and a raycast hits the humanoid

heres a locker model, the purple part blocks the raycast (the purple part actually only surrounds the locker up to very small increments above, its just scaled for visiblity

image

rebound the entity backwards when it attacks the player?

no, when it reaches the last door, instead of opening it, rebound and then after reaching its spawn point, rebound again and guide it to the last door as if it just spawned in. repeat 3 times, and then open the door

i just dont know how to do it myself