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

so did you see he move at red line like you said?
or he didn’t even spawn, im so confused by despawned when it reaches void.new

sorry.

oh

theres lines in the void.new function that will unanchor the entity, and disable his effects. thats what i mean by despawning

i see him complete the red line, but the orange line does not complete. he just despawns

ok try this, here’s entire script

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) 
	Void.Navigate(enemyModel, maxNum, prevNum, 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

still falls through the ground and despawns

i think i figured it out (probably)
let’s hope this works

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, backward)
	for i=prevNum, maxNum do
		
		local room = generatedRooms[i]
		if backward then
			Void.LerpTo(model, room.Exit)
		else
			Void.LerpTo(model, room.Enterance)
		end
		
		
		local waypoints = room:FindFirstChild("Waypoints")
		if waypoints then
			for i=1, #waypoints:GetChildren() do
				Void.LerpTo(model, waypoints[i])
			end
		end
		
		if backward then
			Void.LerpTo(model, room.Enterance)
		else
			Void.LerpTo(model, room.Exit)
		end
	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, false) 
	Void.Navigate(enemyModel, maxNum, prevNum, generatedRooms, true) 
	
	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

im getting lunch rn, so ill be afk for like 10-15 minutes, ill test it when im back

STILL despawned after reaching the farthest door…

trying some tweaks on it to see if it will work

i got the script to work partially, for some reason the backwards part is a one time use

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, backward)
	for i=prevNum, maxNum do
		local prevRoom = generatedRooms[prevNum]
		local room = generatedRooms[i]
		if backward then
			Void.LerpTo(model, prevRoom.Exit)
		else
			Void.LerpTo(model, room.Enterance)
		end


		local waypoints = room:FindFirstChild("Waypoints")
		if waypoints then
			for i=1, #waypoints:GetChildren() do
				Void.LerpTo(model, waypoints[i])
			end
		end

		if backward then
			Void.LerpTo(model, prevRoom.Enterance)
		else
			Void.LerpTo(model, room.Exit)
		end
	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, false) 
	Void.Navigate(enemyModel, maxNum, prevNum, generatedRooms, true) 
	Void.Navigate(enemyModel, prevNum, maxNum, generatedRooms, false) 

	local lastDoor = maxRoom.Door
	lastDoor.OpenEvent:Fire()
	
	wait(10)
	enemyModel.Void.Anchored = false
	enemyModel.Particles.Anchored = false
	enemyModel.Particles.Void.Enabled = false
	enemyModel.Void.CanCollide = false
	enemyModel.Particles.CanCollide = false
end

return Void

even if i add more backwards navigates

edit: for some reason this statement was false on the second attempt, but not on the third

the rebound now works, but only partially, when it goes backwards, it goes directly to the enterance of the last tenth room, and it doesnt look very clean

1 Like
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, backward)
	local function go(i)
		local room = generatedRooms[i]
		if backward then
			Void.LerpTo(model, room.Enterance)
		else
			Void.LerpTo(model, room.Exit)
		end

		--	local waypoints = room:FindFirstChild("Waypoints")
		--	if waypoints then
		--	for i=1, #waypoints:GetChildren() do
		--	Void.LerpTo(model, waypoints[i])
		--	end
		--	end
	end
	
	if backward then
		for i=prevNum, maxNum, -1 do
			go(i)
		end
	else
		for i=prevNum, maxNum do
			go(i)
		end
	end
	
	
end

function Void.new(number, generatedRooms)

	local enemyModel = workspace.Enemies.Void:Clone()

	local prevNum = number - 10
	local maxNum = number + 3
	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, false) 
	Void.Navigate(enemyModel, maxNum, prevNum, generatedRooms, true) 
	Void.Navigate(enemyModel, prevNum, maxNum, generatedRooms, false) 
	Void.Navigate(enemyModel, maxNum, prevNum, generatedRooms, true) 
	Void.Navigate(enemyModel, prevNum, maxNum, generatedRooms, false) 

	enemyModel.Void.Anchored = false
	enemyModel.Particles.Anchored = false
	enemyModel.Particles.Void.Enabled = false
	enemyModel.Void.CanCollide = false
	enemyModel.Particles.CanCollide = false
end

return Void

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