So basically my gun damages players if the ray is in a certain angle, and I don’t know why. Everthing prints, and no errors. Here is my script:
-- local script in gun (tool)
local BODY_DAMAGE = 20
local HEADSHOT = 40
local CLIP = 8
local MAX_BULLETS = 64
local SHOOTY_PART = script.Parent.Shooty
local HandleOfGun = script.Parent.Handle
local Part_1 = script.Parent.Part1
local Part_2 = script.Parent.Part2
local Part_3 = script.Parent.Part3
local Player = game.Players.LocalPlayer
local Character = Player.Character
local mouse = Player:GetMouse()
local Reload = false
script.Parent.Activated:Connect(function()
CLIP = CLIP - 1
if CLIP <= 0 then
Reload = true
CLIP = 8
else
local MousePos = mouse.Hit.p
game.ReplicatedStorage.Shooty:FireServer(Character, HEADSHOT, BODY_DAMAGE, SHOOTY_PART, MousePos, HandleOfGun, Part_1, Part_2, Part_3)
end
end)
-- Server script also in gun (tool)
local debris = game:GetService("Debris")
game.ReplicatedStorage.Shooty.OnServerEvent:Connect(function(player, Character, HEADSHOT, BODY_DAMAGE, SHOOTY_PART, MousePos, HandleOfGun, Part_1, Part_2, Part_3)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {Character, SHOOTY_PART, HandleOfGun, Part_1, Part_2, Part_3, workspace.Baseplate}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local ray = workspace:Raycast(SHOOTY_PART.Position, MousePos - SHOOTY_PART.Position.Unit * 100, raycastParams)
local direction = (MousePos - SHOOTY_PART.Position).Unit * 100
local midPoint = SHOOTY_PART.Position + direction/2
local part = Instance.new("Part")
part.Size = Vector3.new(0.2, 0.2,direction.Magnitude)
part.CFrame = CFrame.new(midPoint, SHOOTY_PART.Position)
part.Anchored = true
part.CanCollide = false
part.Parent = workspace
part.BrickColor = BrickColor.new("New Yeller")
debris:AddItem(part,0.1)
if ray then
local part = ray.Instance
print(part)
local humanoid = part.Parent:FindFirstChild("Humanoid") or part.Parent.Parent:FindFirstChild("Humanoid")
print("HumanoidFound")
if humanoid then
humanoid:TakeDamage(math.random(10,20))
end
end
end)
Help is appreciated and if you have questions, please ask me