Mouse trailer ? Need some help

So I have been making a mouse trailer with some help from the people here, but I have a huge problem that being when it scales it looks so wierd since I can only make it with squares and not other shapes any ideas ?
image

Script:

local MouseTrailModule = {}
MouseTrailModule.__index = MouseTrailModule

local UserInputService = game:GetService(“UserInputService”)
local RunService = game:GetService(“RunService”)
local Debris = game:GetService(“Debris”)
local TweenService = game:GetService(“TweenService”)
local Players = game:GetService(“Players”)

–local Trove = require(game.ReplicatedStorage.Packages.Trove)

function MouseTrailModule.new(_beamDuration : number?)
local self = setmetatable({}, MouseTrailModule)

–self.Trove = Trove.new()

self.player = Players.LocalPlayer
self.playerGui = self.player:WaitForChild(“PlayerGui”)
self.screenGui = self.playerGui:FindFirstChild(“MouseScreenGui”) or Instance.new(“ScreenGui”,self.playerGui)
self.screenGui.Name = “MouseScreenGui”

–self.Trove:Add(self.screenGui,“Destroy”)

self.mouse = self.player:GetMouse()

self.beamDuration = _beamDuration or 0.2
self.previous_mousePosition = nil

self.Connection = nil

–self.Trove:Add(self.Connection,“Disconnect”)

return self
end

function MouseTrailModule:Enable()

local function Tween(object, duration, properties)
local tweenInfo = TweenInfo.new(duration, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local tween = TweenService:Create(object, tweenInfo, properties)
tween:Play()
end

local function Make_Trail_Frame(Point1, Point2)
local Position1, Position2 = UDim2.fromOffset(Point1.X, Point1.Y), UDim2.fromOffset(Point2.X, Point2.Y)
local Trail = Instance.new(“Frame”)
Trail.BorderSizePixel = 0
Trail.BackgroundColor3 = Color3.new(128, 128, 128) – White interior color
Trail.Parent = self.screenGui
Trail.AnchorPoint = Vector2.new(0.5, 0.5)

  Trail.Position = Position1:Lerp(Position2, 0.5)
  local length = (Point1 - Point2).Magnitude + 6
  local thickness = math.min(20, 5 + (Point1 - Point2).Magnitude / 5 * 20)
  Trail.Size = UDim2.fromOffset(length, thickness)
  Trail.Rotation = math.deg(math.atan2((Point1 - Point2).Y, (Point1 - Point2).X))

  -- Apply UIGradient for the fade effect
  local gradient = Instance.new("UIGradient")
  gradient.Color = ColorSequence.new({
  	ColorSequenceKeypoint.new(0, Color3.fromRGB(128, 128, 128)),  -- White at the edges
  	ColorSequenceKeypoint.new(0.2, Color3.fromRGB(255, 255, 255)),  -- Gray in the middle
  	ColorSequenceKeypoint.new(0.8, Color3.fromRGB(255, 255, 255)),  -- Gray in the middle
  	ColorSequenceKeypoint.new(1, Color3.fromRGB(128, 128, 128))   -- White at the edges
  })
  gradient.Rotation = 90  -- Adjust if needed to match the orientation of the trail
  gradient.Parent = Trail

  local corner = Instance.new("UICorner")
  corner.CornerRadius = UDim.new(0.5, 0) -- Make the frame round
  corner.Parent = Trail

  return Trail

end

self.Connection = RunService.RenderStepped:Connect(function()
if self.previous_mousePosition == nil then self.previous_mousePosition = UserInputService:GetMouseLocation() return end

  local mousePosition = UserInputService:GetMouseLocation()
  if mousePosition == self.previous_mousePosition then return end
  local Trail = Make_Trail_Frame(mousePosition,self.previous_mousePosition)
  Tween(Trail,self.beamDuration,{Size = UDim2.fromOffset((mousePosition-self.previous_mousePosition).Magnitude,0),BackgroundColor3 = Color3.fromRGB(255, 255, 255)}) ---BackgroundTransparency = 1,
  Debris:AddItem(Trail,self.beamDuration)
  
  -- trb sa pun un romb care se uit in directia in care se misca moseul deci iau pozitia veche cu pozitia actuala si vad orientarea
  -- trb scalat sa nu fie la fel de mare sa i pun gradient ca la trail

  self.previous_mousePosition = mousePosition

end)
self.mouse.Icon = “”
end

function MouseTrailModule:Disable()
if self.Conneciton then
self.Connection:Disconnect()
self.Connection = nil
end
self.mouse.Icon = “rbxasset://SystemCursors/Arrow”
end

function MouseTrailModule:Destroy()
self:Disable()
–self.Trove:Destroy()
end

return MouseTrailModule

1 Like

Hiya! It’s me again…

First of all I would like to tell you to please format your code using codeblocks like so:

-- This is a code block. It is made by putting three backquotes ("`") above and below your code!

Second:

Explaination

To make this you first need to create a trail part. Make it super small and make the attachments distance EXTREMELY small, roughly 0.01 studs apart.

Then use a runService loop with Camera:ScreenPointToRay() which would basically get the position specified in x and y coordinated in the 3d workspace. Here is the code I used:

RunService.RenderStepped:Connect(function()
	local mousePosition = UserInputService:GetMouseLocation()
	local mouseUnitRay = Camera:ScreenPointToRay(mousePosition.X,mousePosition.Y-50,0.1)
end)

I have a -50 offset because of the topbar.

Then you can position the part like so:

Trail.CFrame = CFrame.new(mouseUnitRay.Origin,Camera.CFrame.Position)

I used CFrame to keep the part facing the camera at all times.

You can then cutomize the trail as you want and now you can also use images and also make it buttery smooth!!

ok, thank you for the idea, will see what I can do to it

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