Hello,
I am just curious if that above title is possible?
If so, anyone point me in a direction? I have my raycast code already.
Basically the meat and tators of it all.
RayGunEvent.OnServerEvent:connect(function(player, AmmoAmt, target, tool, RayColor, Head, Torso, Limb)
AmmoAmt.Value = AmmoAmt.Value - 1
local user = tool.Parent
local ray = Ray.new(tool.MuzzleFlash.CFrame.p, (target - tool.MuzzleFlash.CFrame.p).unit * 900)
local hit, position = game.Workspace:FindPartOnRay(ray, user)
local distance = (position - tool.MuzzleFlash.CFrame.p).magnitude
local RayPart = Instance.new("Part", user)
RayPart.Name = "BulletPath"
RayPart.BrickColor = RayColor
RayPart.Transparency = 1
RayPart.Material = "Neon"
RayPart.Anchored = true
RayPart.CanCollide = false
RayPart.TopSurface = Enum.SurfaceType.Smooth
RayPart.BottomSurface = Enum.SurfaceType.Smooth
RayPart.formFactor = Enum.FormFactor.Custom
RayPart.Size = Vector3.new(0.01, 0.01, distance)
RayPart.CFrame = CFrame.new(position, tool.MuzzleFlash.CFrame.p) * CFrame.new(0, 0, -distance/2)
game.Debris:AddItem(RayPart, 0.1)
if target then
local splash = Instance.new("Part", game.Workspace)
splash.Name = "BulletHole"
splash.Anchored = true
splash.Transparency = 1
splash.CanCollide = false
splash.Size = Vector3.new(0.001,0.001,0.001)
splash.CFrame = CFrame.new(target)
local Dusty = script.DustEmitter:Clone()
Dusty.Enabled = true
Dusty.Parent = splash
Debris:AddItem(splash, 1)
end
local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid")
if humanoid and humanoid:FindFirstChild("Health") then
local BloodSpatter = Instance.new("Part", game.Workspace)
BloodSpatter.Name = "BulletHole"
BloodSpatter.Anchored = true
BloodSpatter.Transparency = 1
BloodSpatter.CanCollide = false
BloodSpatter.Size = Vector3.new(0.2,0.2,0.2)
BloodSpatter.CFrame = CFrame.new(target)
local Blood = script.BloodEmitter:Clone()
Blood.Enabled = true
Blood.Parent = BloodSpatter
Debris:AddItem(BloodSpatter, 2)
if hit.Name == "Head" then
humanoid.Health = humanoid.Health - Head
elseif hit.Name == "Torso" then
humanoid.Health = humanoid.Health - Torso
else
humanoid.Health = humanoid.Health - Limb
end
end
end)

3 comments
So you want a projectile to travel along the ray?
You can tween the trail part with TweenService
Yeah, a projectile to travel along the ray would be more...realistic?