Problems with visualisating

Hello! I’m trying to make a dash ability skill, but you can charge it to make the dash travel longer. So the problem I have right now is trying to show the player where he will end up accurately. I tried to search up for it on DevForum but couldnt find anything that could help me.

For dash I use BodyVelocity and for visualisating I use Beam.

Please, keep in mind that all scripts below are just summary of how it works

Dash script
function Dash(Config: {Dir: Vector3, Power: number, Time: number})
	local Character = Player.Character
	local HumanoidRootPart = Character.HumanoidRootPart
	local RootAttachment = HumanoidRootPart.RootAttachment

	if not Config.Dir then
		Config.Dir = HumanoidRootPart.CFrame.LookVector
	end
	
	if HumanoidRootPart:FindFirstChild("KBV") then
		HumanoidRootPart.KBV:Destroy()
	end

	local KBV = Instance.new("BodyVelocity")
	KBV.Name = "KBV"
	KBV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	KBV.Velocity = Config.Dir * (Config.Power)
	KBV.Parent = HumanoidRootPart
	Debris:AddItem(KBV, Config.Time or 0.1)
end
Beam script
function ShowBeam(StartLength: number, EndLength: number, Step: number)
	if not Step then Step = 1 end
	local CurrentLength = StartLength

	local Beam = Effects.AimBeam:Clone()
	local A0 = Instance.new("Attachment")
	A0.Name = "VA0"
	local A1 = Instance.new("Attachment")
	A1.Name = "VA1"
	A0.Position = Vector3.new(0, -2.9, 0)
	A0.Orientation = Vector3.new(0, 0, 90)
	A0.Parent = Player.Character.HumanoidRootPart
	A1.Position = Vector3.new(0, -2.9, -CurrentLength)
	A1.Orientation = Vector3.new(0, 0, 90)
	A1.Parent = Player.Character.HumanoidRootPart
	Beam.Parent = A0
	Beam.Attachment0 = A0
	Beam.Attachment1 = A1

	while Beam and Beam.Parent and CurrentLength < EndLength do
		local DeltaTime = RunService.Heartbeat:Wait()
		CurrentLength += Step * DeltaTime
		if CurrentLength > EndLength then CurrentLength = EndLength end
		A1.Position = Vector3.new(0, -2.9, -CurrentLength)
	end
end
Ability script
local StartPower = 30
local PassedTime = 0
task.spawn(ShowBeam, 6, 20)

while Character:GetAttribute("Charging") == true do
	local DeltaTime = RunService.Heartbeat:Wait()
	PassedTime += DeltaTime
end
Player.Character.HumanoidRootPart.VA0:Destroy()
Player.Character.HumanoidRootPart.VA1:Destroy()
local NewPower = math.clamp(30 + PassedTime, 0, 100)
Dash({Power = NewPower, Time = 0.2})

Here’s a video of how it looks

Hello!’
Im not a scripter (I didn’t read the code) but what if you used a math function that gradually updates the player’s location so they end up at the same location as the end attachment of the beam?

Yea I solved the problem with doing something like this. Its much more reliable.

The reason you’re having trouble is likely because the Beam length and the Dash distance are being calculated independently. Since you are using BodyVelocity, the math is actually pretty straightforward.

In your Dash function, your distance is defined by: Distance = Power × Time

If your dash lasts for 0.2 seconds (as seen in your script), and your power is 100, you will travel exactly 20 studs. To make the beam accurate, you shouldn’t just “guess” the length; you should calculate it based on what the NewPower will be.

How to fix it
In your Habilidade Script, you are calculating NewPower after the loop ends. To show the prediction in real-time, you should move that calculation inside the loop and update the Beam’s attachment accordingly.

Try something like this:

local StartPower = 30
local DashTime = 0.2 -- Keep this consistent with your Dash function
local PassedTime = 0

-- Start the beam
task.spawn(ShowBeam, 6, 20) 

while Character:GetAttribute("Charging") == true do
    local DeltaTime = RunService.Heartbeat:Wait()
    PassedTime += DeltaTime
    
    -- Calculate what the power WOULD be if we let go now
    local PredictedPower = math.clamp(StartPower + (PassedTime * 50), 30, 100) 
    local ExactDistance = PredictedPower * DashTime
    
    -- Update your A1 Attachment position to match ExactDistance
    if Character.HumanoidRootPart:FindFirstChild("VA1") then
        Character.HumanoidRootPart.VA1.Position = Vector3.new(0, -2.9, -ExactDistance)
    end
end

Pro Tip: Walls and Obstacles
One thing to keep in mind: BodyVelocity will stop you if you hit a wall, but your Beam will go right through it. To make it look “pro,” you can use a simple Raycast inside that loop to cap the ExactDistance if there’s a wall in the way.

local raycastResult = workspace:Raycast(HumanoidRootPart.Position, Direction * ExactDistance, params)
if raycastResult then
    -- Set Beam length to raycastResult.Distance
end

This way, the player sees exactly where they’ll thud against a wall or land in the open. Hope this helps