Basicly when you are not walking and you shoot the beam looks fine but when you walk and you shoot looks kinda broken.
this:
I dont know how I can fix I tried to change the position but nothing.
Script:
local range = 400
local NormalDamage = 50
local HeadDamage = 65
local debounce = false
game.ReplicatedStorage.ToolsEvent.RayGunShootEvent.OnServerEvent:Connect(function(Player, TargetLocation, BulletLocation)
if Player.Character == nil then
return
end
local Beam = Instance.new("Part", game.Workspace)
Beam.Color = Color3.fromRGB(0, 255, 0)
Beam.Transparency = 0
Beam.FormFactor = "Custom"
Beam.Material = "Neon"
Beam.Anchored = true
Beam.CanCollide = false
local distance = (BulletLocation.Position - TargetLocation).magnitude
Beam.Size = Vector3.new(0.1, 0.1, distance)
Beam.CFrame = CFrame.new(BulletLocation.Position, TargetLocation) * CFrame.new(0, 0, -distance/2)
game.Debris:AddItem(Beam, 0.1)
local NewRay = RaycastParams.new()
local RayDirection = (TargetLocation - BulletLocation.Position) * range
NewRay.FilterDescendantsInstances = {Player.Character}
local Result = game.Workspace:Raycast(BulletLocation.Position, RayDirection, NewRay)
local humanoid = Result.Instance.Parent:FindFirstChild("Humanoid")
if Result then
if Result.Instance then
if not humanoid then
return
end
if Result.Instance.Name == "Head" then
humanoid.Health -= HeadDamage
local tag = Instance.new("ObjectValue")
tag.Name = "creator"
tag.Value = Player
tag.Parent = humanoid
elseif humanoid then
humanoid.Health -= NormalDamage
local tag = Instance.new("ObjectValue")
tag.Name = "creator"
tag.Value = Player
tag.Parent = humanoid
end
end
end
end)