[SOLVED] How can i make the entity rebound? (rooms fan-made) (reuploaded)

i followed a tutorial from @GnomeCode

the entity im talking about is named “the void”, he 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

I remembered this, sorry, I forgot to answer your question

I don’t understand what do you mean by that, I never played rooms before
can you explain it more?

if you’ve played doors before, im kind of going for an ambush AI makeshift from the tutorial code

sorry, I never played that too

lemme get a sample video from online, ill paste it in

probably cant do that, ill draw a little sample

the red line represents the void.Navigate part of the code. i just dont know how to code the orange line.

each block represents 2 rooms

char limit

okay

do you mean smiler do rebound?

smiler is a rush entity, meaning he just goes to the last door, then despawns

the void entity is the one im trying to get to rebound

ok so it’s red line go to last opened door and orange line is just going back to its spawn location?

pretty much
i dont have a spawn part, its spawn location is 10 rooms from the last opened door

heres the explorer for one room, the enterance and exit parts are the only important factors in moving the entity. the lockers just serve for blocking the entity’s raycast that kill the players, while also serving as a hiding spot

image

from what i understand
this should work

function Void.Navigate(model, prevNum, maxNum, generatedRooms)
	local function goTo(i)
		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
	for i=prevNum, maxNum do
		goTo(i)
	end
	for i=maxNum, prevNum do
		goTo(i)
	end
end

thanks for the code, and im so sorry to say

i just want a function that will make the entity move back 10 rooms after it reaches the last door

ill paste this in anyway, what line do i paste it in?

do i just paste it in place of the previous function?

replace the entire Void.Navigate function

he ends up despawning anyway, it continues on through the rest of the code

dont get me wrong, it doesnt throw any errors, it just doesnt make a difference

what do you mean? when do he despawn?

when it reaches the void.new function

heres the server script that handles entity spawning, as well as room generation

local room = require(script.Room)
local door = require(script.Room.Door)
local smiler = require(script.Smiler)
local void = require(script.Void)
local prevRoom = workspace.StartRoom
local playerEnter = script.Room.PlayerEnter
local firstDoor = door.New(prevRoom, 1)

local generatedRooms = {prevRoom}

for i=2, 100 do
	prevRoom = room.Generate(prevRoom, i)
	generatedRooms[i] = prevRoom
	task.wait(0.05)
end

print(generatedRooms)

playerEnter.Event:Connect(function(number)
	if number % 12 == 0 then
		void.new(number, generatedRooms)
	end
end)