Hello. I am trying to re create a visual stun effect that would look something like this, the screenshot is from the game jailbreak
what I currently have looks like this
The issue I would like to correct is in how the parts do not originate at the end of the previous part, I would like to make it so that my recreation of it would do that too
code:
local mouse = game.Players.LocalPlayer:GetMouse()
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local parmas = RaycastParams.new()
parmas.FilterType = Enum.RaycastFilterType.Exclude
parmas.FilterDescendantsInstances = {game.Players.LocalPlayer.Character}
local partNum = 10
local parts = {}
function getRandomRot()
return CFrame.Angles(math.rad(math.random(-15,15)),math.rad(math.random(-15,15)),math.rad(math.random(-15,15)))
end
mouse.Button1Down:Connect(function()
local screenRay = game.Workspace.CurrentCamera:ScreenPointToRay(mouse.X, mouse.Y)
local rayResult = game.Workspace:Raycast(screenRay.Origin, screenRay.Direction * 10000, parmas)
if not rayResult then
return
end
local direction = (rayResult.Position - char.HumanoidRootPart.Position).Unit
local prevPart
local newPart = Instance.new("Part", workspace)
newPart.Anchored = true
newPart.Position = rayResult.Position
newPart.Size = Vector3.new(0.1,0.1,2)
newPart.CFrame = CFrame.new(rayResult.Position, rayResult.Position + screenRay.Direction)
newPart.CFrame = CFrame.lookAt(newPart.Position, char.HumanoidRootPart.Position)
prevPart = newPart
newPart.Color = Color3.new(0.984314, 1, 0.0117647)
table.insert(parts, newPart)
local distanceToPlr = (newPart.Position - char.HumanoidRootPart.Position).Magnitude
repeat
local newPart = Instance.new("Part", workspace)
newPart.Anchored = true
newPart.Size = Vector3.new(0.1, 0.1, math.random(1,3))
newPart.CFrame = prevPart.CFrame + prevPart.CFrame.LookVector * prevPart.Size.Z/2
newPart.CFrame = CFrame.lookAt(newPart.Position, char.HumanoidRootPart.Position)
newPart.CFrame = newPart.CFrame * getRandomRot()
newPart.Color = Color3.new(0.984314, 1, 0.0117647)
newPart.CanCollide = false
newPart.CanCollide = false
table.insert(parts, newPart)
distanceToPlr = (newPart.Position - char.HumanoidRootPart.Position).Magnitude
prevPart = newPart
until distanceToPlr <= 1
task.wait(0.1)
for i,v in pairs(parts) do
v:Destroy()
end
end)
help is appreciated


