How to make a trail that follows the player

In my game, I have these heal and damage bricks, and I wonder how I could make it so when the player gets close enough to the bricks, a trail will spawn from the brick and attach to the player, and when they get out of radius, the trail will be removed. Here is an image of what im trying to make: (Im not sure the best way to do this)

Here is the current code I have so far:

local CollectionService = game:GetService("CollectionService")
local Players = game:GetService("Players")

local brickCooldown = .1

local function getPlayersInRadius(part: BasePart)
	local playerTable = {}
	for _, player in pairs(Players:GetPlayers()) do
		local character = player.Character
		if not character then
			continue
		end
		local distance = (part.Position - character.HumanoidRootPart.Position).Magnitude
		if distance < part:GetAttribute("TriggerDistance") then
			table.insert(playerTable, character)
		end
	end
	return playerTable
end

while task.wait(brickCooldown) do
	for _, part in CollectionService:GetTagged("Damage Brick") do
		for _, player in pairs(getPlayersInRadius(part)) do
			player.Humanoid:TakeDamage(.5)
		end
	end
	for _, part in CollectionService:GetTagged("Heal Brick") do
		for _, player in pairs(getPlayersInRadius(part)) do
			player.Humanoid.Health += .5
		end
	end
end

creating a beam attached to the players torso would probably be the best way to do this

2 Likes

Nah, a beam is different from a Trail. just find out how to use Trails and you’re good.

2 Likes

Did you figure out the solution yet?

1 Like

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