I used a basic fastcast script to fire projectiles but for some reason it drops the heartbeat down to almost 10, what am I doing wrong? In the video the hearbeat fluctuate because of OBS but without OBS its solid 57+
The script:
--\\ Written By GeraldIn2016 \\--
local FastCast = require(game:GetService("ReplicatedStorage"):FindFirstChild("Gerald's Library", true):FindFirstChild("FastCastRedux",true))
local PartCache = require(game:GetService("ReplicatedStorage"):FindFirstChild("Gerald's Library", true):FindFirstChild("PartCache",true))
local bulletsFolder = workspace:FindFirstChild("BulletFolder") or Instance.new("Folder", workspace)
bulletsFolder.Name = "BulletFolder"
local FireSound = script.Parent.Fire
local Debris = game:GetService("Debris")
local bulletTemplate = Instance.new("Part")
bulletTemplate.Material = Enum.Material.Neon
bulletTemplate.Color = Color3.fromRGB(255, 255, 204)
bulletTemplate.CanCollide = false
bulletTemplate.Anchored = true
bulletTemplate.Size = Vector3.new(0.2, 0.2, 10)
--FastCast.VisualizeCasts = true
local caster = FastCast.new()
local castParams = RaycastParams.new()
castParams.FilterType = Enum.RaycastFilterType.Blacklist
castParams.IgnoreWater = true
local bulletCache = PartCache.new(bulletTemplate, 100, bulletsFolder)
local castBehavior = FastCast.newBehavior()
castBehavior.RaycastParams = castParams
castBehavior.Acceleration = Vector3.new(0, -workspace.Gravity/6, 0)
castBehavior.AutoIgnoreContainer = false
castBehavior.CosmeticBulletContainer = bulletsFolder
castBehavior.CosmeticBulletProvider = bulletCache
castBehavior.MaxDistance = 200
local muzzleFlash = game:GetService("ReplicatedStorage"):WaitForChild("MuzzleFlash")
local showing = false
function PlayFireSound()
local NewSound = FireSound:Clone()
NewSound.Parent = script.Parent
NewSound:Play()
Debris:AddItem(NewSound, NewSound.TimeLength)
if showing == false then
showing = true
local flash = muzzleFlash:Clone()
flash.Parent = script.Parent.Parent.Gun.Main
flash.Position =script.Parent.Parent.Gun.Barrel.Position
delay(0.4, function()
flash:Destroy()
showing = false
end)
end
end
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 function onRayHit(cast, result, velocity, bullet)
local hit = result.Instance
local character = hit:FindFirstAncestorWhichIsA("Model")
if character and character:FindFirstChild("Humanoid") then
character.Humanoid:TakeDamage(50)
end
end
--[[
local function fire(player, mousePosition)
local origin = firePoint.WorldPosition
local direction = (mousePosition - origin).Unit
caster:Fire(origin, direction, 1000, castBehavior)
end]]
local cooldown = false
local firing = false
script.Parent.FireEvent.OnServerEvent:Connect(function (clientThatFired, firingGun)
firing = firingGun
end)
function OnRayTerminated(cast)
local cosmeticBullet = cast.RayInfo.CosmeticBulletObject
delay(0.5, function()
bulletCache:ReturnPart(cosmeticBullet)
end)
end
script.Parent:GetPropertyChangedSignal("Occupant"):Connect(function()
if script.Parent.Occupant == nil then
firing = false
return
end
end)
spawn(function()
while true do
wait(0.1)
print(firing)
if cooldown == false and firing == true then
cooldown = true
print("FIRING")
local mouseDirection = ( script.Parent.Parent.Gun.Barrel.Position - script.Parent.Parent.Gun.Main.Position).Unit
spawn(function()
caster:Fire(script.Parent.Parent.Gun.Barrel.Position, mouseDirection, 500, castBehavior)
end)
PlayFireSound()
delay(0.1, function()
cooldown = false
end)
end
end
end)
--fireEvent.OnServerEvent:Connect(fire)
--tool.Equipped:Connect(onEquipped)
castParams.FilterDescendantsInstances = {script.Parent.Parent.Gun}
caster.LengthChanged:Connect(onLengthChanged)
caster.RayHit:Connect(onRayHit)
caster.CastTerminating:Connect(OnRayTerminated)
Any ideas? Ignore the bad FPS my recording software settings were all wrong.