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