Lags the game in 2 ways:
Server lag and Client lag ( tested on 3 computers, all of them lag when the player shoots somebody or you get shot, and the server lags aswell)
local caster = FastCast.new()
local castParams = RaycastParams.new()
castParams.FilterType = Enum.RaycastFilterType.Blacklist
castParams.IgnoreWater = true
local castBehavior = FastCast.newBehavior()
castBehavior.RaycastParams = castParams
castBehavior.Acceleration = Vector3.new(0, 0, 0)
castBehavior.AutoIgnoreContainer = false
castBehavior.CosmeticBulletContainer = bulletsFolder
castBehavior.CosmeticBulletTemplate = bulletTemplate
castParams.FilterDescendantsInstances = {IgnoreModule}
caster.LengthChanged:Connect(onLengthChanged)
caster.RayHit:Connect(function(cast, result, normal, bullet)
local hit = result.Instance
print("Hit"..hit.Name)
local character = hit:FindFirstAncestorWhichIsA("Model")
bullet:Destroy()
if character:FindFirstChild("Humanoid") and character.Humanoid.Parent.Name == script.Parent.Parent.Name then
return
else
if character and character:FindFirstChild("Humanoid") and hit.Name == "Head" or hit.Name == "HeadCollision" then
character.Health.bleeding.Value = true
character.Health.BleedRate.Value = character.Health.BleedRate.Value - 35
character.Health.Damage.Value = character.Health.Damage.Value + 35
local HeadshotAnim = character.Humanoid:LoadAnimation(script.PainAnimations.Headshot)
print("Headshot")
local HitSound = script.Headshot:Clone()
HitSound.Parent = hit
bmod:damage(hit, "Knock", tool)
HitSound:Play()
HitSound.Ended:Connect(function()
HitSound:Destroy()
end)
character.Humanoid.Health = character.Humanoid.Health - 90
HeadshotAnim:Play()
local Creator_Tag = Instance.new("ObjectValue")
Creator_Tag.Name = "creator"
Creator_Tag.Value = tool.Parent
Creator_Tag.Parent = character.Humanoid
local hitplayer = game.Players:GetPlayerFromCharacter(character)
local shootingplayer = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
game.ReplicatedStorage.Material_Notify_Storage.MaterialEvent:FireClient(hitplayer, 1, "Error", "You've been shot in the ".."Head".." for 90 damage!", 5)
bullet:Destroy()
game.ReplicatedStorage.Material_Notify_Storage.MaterialEvent:FireClient(shootingplayer, 1, "Success", "You shot ".. character.Name .." in the Head for 90 damage.", 5)
character.Health.bledout.Value = true
character.Health.bledout.Value = false
game:GetService("Debris"):AddItem(Creator_Tag, 5)
else
if character and character:FindFirstChild("Humanoid") and hit.Name ~= "Head" then
character.Health.BleedRate.Value = character.Health.BleedRate.Value - tool.Variables.Damage.BleedRate.Value
character.Health.bleeding.Value = true
character.Health.Damage.Value = character.Health.Damage.Value + tool.Variables.Damage.BleedDmg.Value
bmod:damage(hit, "Wound", tool)
character.Health.bledout.Value = true
character.Health.bledout.Value = false
local HitSound = script.Bodyshot:Clone()
HitSound.Parent = hit
HitSound:Play()
HitSound.Ended:Connect(function()
HitSound:Destroy()
end)
bullet:Destroy()
bullet.Orientation = Vector3.new(0,0,0)
character.Humanoid.Health = character.Humanoid.Health - tool.Variables.Damage.Value
local Creator_Tag = Instance.new("ObjectValue")
Creator_Tag.Name = "creator"
Creator_Tag.Value = tool.Parent
Creator_Tag.Parent = character.Humanoid
local hitplayer = game.Players:GetPlayerFromCharacter(character)
local shootingplayer = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
if hit.Name == "HumanoidRootPart" then
game.ReplicatedStorage.Material_Notify_Storage.MaterialEvent:FireClient(hitplayer, 1, "Error", "You've been shot in the UpperTorso for".." "..tool.Variables.Damage.Value.." ".."damage!", 5)
else
game.ReplicatedStorage.Material_Notify_Storage.MaterialEvent:FireClient(hitplayer, 1, "Error", "You've been shot in the".." "..hit.Name.." ".."for".." "..tool.Variables.Damage.Value.." ".."damage!", 5)
end
game.ReplicatedStorage.Material_Notify_Storage.MaterialEvent:FireClient(shootingplayer, 1, "Success", "You shot ".. character.Name .." in the ".. hit.Name .. " for ".. tool.Variables.Damage.Value.. " damage.", 5)
bullet:Destroy()
game:GetService("Debris"):AddItem(Creator_Tag, 5)
end
end
end
game:GetService("Debris"):AddItem(bullet, 2)
end)
My gun system uses FastCast, but I need help, this is really game breaking and I am not able to release until I get this fixed. Super laggy, I didn’t record it tho. I tried deleting the blood, but it didn’t help so I honestly don’t know.