-----SERVER SCRIPT------
local tool = script.Parent
local active = tool.activeevent
local fastcast = require(game.ServerStorage.FastCastRedux)
--fastcast.VisualizeCasts = true
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
tool.Equipped:Connect(function()
params.FilterDescendantsInstances = {tool.Parent,tool.Handle,tool.Parent:GetChildren()}
end)
active.OnServerEvent:Connect(function(plr,p1,p2)
local bullet = game.ReplicatedStorage.Bullet.toolbullet:Clone()
bullet.Parent = workspace
local orgin = tool.Handle.Position
local caster = fastcast.new()
local dire = p2
local behave = caster.newBehavior(params)
caster:Fire(orgin,dire,150,behave)
caster.LengthChanged:Connect(function(cast, last, dire, length)
local blength = bullet.Size.Z/2
local offset = CFrame.new(0,0,-(length-blength))
bullet.CFrame = CFrame.lookAt(last,last+dire):ToWorldSpace(offset)
end)
caster.RayHit:Connect(function(ray, result)
local hit = result.Instance
print(hit)
local char = hit:FindFirstAncestorOfClass('Model') or hit.Parent
if char.Name == plr.Name then return end
local hum = char:FindFirstChild('Humanoid')
if hum then
hum.Health = 0
end
bullet:Destroy()
end)
end)