Server Script
local FastCast = require(game.ServerStorage:WaitForChild("Modules"):WaitForChild("FastCastRedux"))
local CastEvent = script.Parent:WaitForChild("CastEvent")
local CastParams = RaycastParams.new()
local BulletCache = game.Workspace:WaitForChild("BulletCache")
local BulletPart = game.ServerStorage:WaitForChild("Projectiles"):WaitForChild("Bullet")
local ShootPoint = script.Parent:WaitForChild("ShootPoint")
local BulletSpeed = 800
local MuzzleParticle = script.Parent.Parent:WaitForChild("MuzzleFlash"):WaitForChild("FlashParticle")
local MuzzleLight = script.Parent.Parent:WaitForChild("MuzzleFlash"):WaitForChild("FlashLight")
local function OnLengthChanged(cast, lastPoint, direction, length, velocity, bullet)
if bullet then
local bulletLength = bullet.Size.Z/2
local offset = CFrame.new(0,0, (length - bulletLength))
bullet.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
end
end
local Caster = FastCast.new()
local CasterBehavior = FastCast.newBehavior()
CasterBehavior.RaycastParams = CastParams
CasterBehavior.Acceleration = Vector3.new(0,0,0)
CasterBehavior.AutoIgnoreContainer = false
CasterBehavior.CosmeticBulletContainer = BulletCache
CasterBehavior.CosmeticBulletTemplate = BulletPart
CastEvent.OnServerEvent:Connect(function(Player, MouseHit)
local Direction = (ShootPoint.WorldCFrame.Position - MouseHit).Unit
Caster:Fire(ShootPoint.WorldCFrame.Position,MouseHit, BulletSpeed, CasterBehavior)
MuzzleParticle:Emit(3)
MuzzleLight.Enabled = true
task.wait(0.035)
MuzzleLight.Enabled = false
end)
Caster.RayHit:Connect(function(cast, result, velocity, bullet)
local hit = result.Instance
if hit.Parent:FindFirstChild("Humanoid") then
print("hit a player")
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(25)
end
bullet:Destroy()
end)
Caster.LengthChanged:Connect(OnLengthChanged)
** You are now Level 2! **