I made a gun using the FastCast Module. Problem im having is for some reason its very hard to hit a player, even when trying to hit a stationary target. Heres a clip of me trying to hit another player. The other player is stationary and my bullet is clearly hitting the player but not doing anything.
https://gyazo.com/c1d89616bae264e3cad7e2ee995bd70b
Q: Can you hit the player at all?
A: Yes, but it is very hard. I would have to get a good distance to get a hit.
Here is my code (only the important parts and this is local):
function canraypierce(hitPart, hitPoint, normal, material)
if (hitPart.Name == "Bullet" or (hitPart.Transparency == 1 and not hitPart.Parent:FindFirstChild("Humanoid")) or (hitPart.CanCollide == false and not hitPart.Parent:FindFirstChild("Humanoid")) or hitPart.Parent:IsA("Accessory")
or (game.Players:GetPlayerFromCharacter(hitPart.Parent) and game.Players:GetPlayerFromCharacter(hitPart.Parent).Team == player.Team and not game.Players:GetPlayerFromCharacter(hitPart.Parent).Neutral))
and hitPart.Name ~= "Head" and hitPart.Name ~= "Torso" then print("pierced "..hitPart.Name) return true end
return false
end
function getdirection(dir)
local RNG = Random.new()
local TAU = math.pi * 2
local minangle = stats.MinAngle
local maxangle = stats.MaxAngle
local directionalCF = CFrame.new(Vector3.new(), dir)
local direction = (directionalCF * CFrame.fromOrientation(0, 0, RNG:NextNumber(0, TAU)) * CFrame.fromOrientation(math.rad(RNG:NextNumber(minangle, maxangle)), 0, 0)).LookVector
return direction
end
wep.Activated:Connect(function()
if not wep.Enabled then return end
holding = true
if db or not character or (character and character.Humanoid.Health == 0) or wep.Parent ~= character or ammo <= 0 then return end
db = true
--determining source and direction
local source = handle.BulletSpawn.WorldPosition
local predirection = (mouse.Hit.p - source).Unit
local direction = getdirection(predirection)
spawn(function()
if not followmouse then
followmouse = true
countdown()
followmouse = false
neck.C0 = oldNeckC0
shoulder.C0 = oldShoulderC0
shoulder2.C0 = oldshoulder2C0
game.ReplicatedStorage.Remotes.GunStopFollow:FireServer(oldNeckC0,oldShoulderC0,oldshoulder2C0)
end
end)
local cb = bullet:Clone()
local cbeam = handle.Beam:Clone()
cbeam.Parent = cb
cbeam.Attachment0 = cb.Attachment0
cbeam.Attachment1 = cb.Attachment1
cbeam.Enabled = false
cbeam.Name = "Beam"
cb.CFrame = CFrame.new(source, source - direction)
cb.Parent = workspace
game.ReplicatedStorage.Remotes.GunEquip:FireServer(handle.Fire)
game.ReplicatedStorage.Remotes.GunShot:FireServer(handle, source, direction * 1024, stats.BulletSpeed, handle.Beam, character, false, Vector3.new(0,0,0), canraypierce, source)
Caster:Fire(source, direction * 1024, stats.BulletSpeed, cb, character, false, Vector3.new(0,0,0), canraypierce)
end)
Caster.LengthChanged:Connect(function(origin, lastPoint, rayDir, displacement, cosmeticBulletObject)
cosmeticBulletObject.CFrame = CFrame.new(lastPoint, origin + rayDir)
if (origin - lastPoint).magnitude > 3 then
cosmeticBulletObject.Beam.Enabled = true
end
end)
Caster.RayHit:Connect(function(hit, point, normal, material, cosmeticBulletObject)
cosmeticBulletObject:Destroy()
if not hit then return end
print(hit.Name)
print(hit.Parent.Name)
if hit.Name == "BreakableGlass" then
game.ReplicatedStorage.Remotes.BreakGlass:FireServer(hit)
elseif hit.Parent:FindFirstChild("Humanoid") then
local dmg = stats.Damage
if hit.Name == "Head" then
dmg = math.ceil(dmg * stats.Headshot)
end
game.ReplicatedStorage.Remotes.WeaponRemotes.DamagePlayer:FireServer(dmg, hit.Parent, handle.Hit, stats.Lines1, stats.Lines2, (point - character.HumanoidRootPart.Position).unit)
end
end)
--some values were indexed somewhere in the localscript
Like you saw in the clip, there were no errors. Can someone explain this? I just learned about FastCast today. Any help will be appreciated!