Hello developers, I am currently working on a FPS game and I’m currently struggling to make good gunplay. whenever 2 players are moving at the same time, the spherecast that I use to create the bullet does not detect anything and shoots in front of the player…?
here is a video
here is my shooting server script inside of server script service
local tweenservice = game:GetService("TweenService")
local shootEvent = game.ReplicatedStorage.Events.Shoot
game:GetService("PhysicsService"):CollisionGroupSetCollidable("ShootingRaycast", "Accessories", false)
game:GetService("PhysicsService"):CollisionGroupSetCollidable("ShootingRaycast", "VM", false)
local bulletholePreset = game.ReplicatedStorage.Assets.BulletHole
local rayParams = RaycastParams.new()
shootEvent.OnServerEvent:Connect(function(player, character, damage, mousePos, vmname, headshotMultiplier, cooldown, armpos, bulletsize, finalpos)
if character then
rayParams.FilterType = Enum.RaycastFilterType.Exclude
rayParams.FilterDescendantsInstances = {character}
rayParams.CollisionGroup = "ShootingRaycast"
local dir = (mousePos - character.Head.Position).Unit * 1023
local ray = workspace:Spherecast(character.Head.Position, bulletsize, dir, rayParams)
if ray then
if ray.Instance then
if ray.Instance.Parent.Name ~= character.Name or ray.Instance.Parent.Parent.Name ~= character.Name then
if ray.Instance.Parent:FindFirstChild("Humanoid") or ray.Instance.Parent.Parent:FindFirstChild("Humanoid") then
if ray.Instance.Name == "Handle" then
if ray.Instance.Parent.Parent:FindFirstChild("Humanoid").Health ~= 0 then
ray.Instance.Parent.Parent:FindFirstChild("Humanoid"):TakeDamage(damage * headshotMultiplier)
if ray.Instance.Parent.Parent.Humanoid.Health <= 0 then
shootEvent:FireClient(player, "dead")
else
shootEvent:FireClient(player, "head")
if game.Players:GetPlayerFromCharacter(ray.Instance.Parent) then
game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("DamageEvent"):FireClient(game.Players:GetPlayerFromCharacter(ray.Instance.Parent), ray.Instance.Position)
end
end
end
elseif ray.Instance.Name == "Head" then
if ray.Instance.Parent.Humanoid.Health ~= 0 then
ray.Instance.Parent.Humanoid:TakeDamage(damage * headshotMultiplier)
if ray.Instance.Parent.Humanoid.Health <= 0 then
shootEvent:FireClient(player, "dead")
else
shootEvent:FireClient(player, "head")
if game.Players:GetPlayerFromCharacter(ray.Instance.Parent) then
game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("DamageEvent"):FireClient(game.Players:GetPlayerFromCharacter(ray.Instance.Parent), ray.Instance.Position)
end
end
end
else
if ray.Instance.Parent.Humanoid.Health ~= 0 then
ray.Instance.Parent.Humanoid:TakeDamage(damage)
if ray.Instance.Parent.Humanoid.Health <= 0 then
shootEvent:FireClient(player, "dead")
else
shootEvent:FireClient(player, "body")
if game.Players:GetPlayerFromCharacter(ray.Instance.Parent) then
game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("DamageEvent"):FireClient(game.Players:GetPlayerFromCharacter(ray.Instance.Parent), ray.Instance.Position)
end
end
end
end
else
local newbullethole = bulletholePreset:Clone()
newbullethole.CFrame = CFrame.new(ray.Position, ray.Position + ray.Normal)
newbullethole.Parent = workspace.BulletHoles
end
end
end
end
if not character.HumanoidRootPart:FindFirstChild(vmname.."Shoot") then
local newsound = game.ReplicatedStorage.Viewmodels:FindFirstChild(vmname).SFX.Shoot:Clone()
newsound.Parent = character.HumanoidRootPart
newsound:Play()
newsound.Name = vmname.."Shoot"
else
character.HumanoidRootPart:FindFirstChild(vmname.."Shoot"):Play()
end
end
end)
if anyone knows a solution to this problem, please help me out. thank you!