local shootEvent = game.ReplicatedStorage.Remotes:FindFirstChild("pistol shoot")
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local shootPart = handle:WaitForChild("Shoot") -- this is your Attachment
local Debris = game:GetService("Debris")
local spread = 0.5
local damage = 10
shootEvent.OnServerEvent:Connect(function(plr, mousePos)
handle.Gunshot:Play()
light()
local origin = shootPart.WorldPosition
local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {plr.Character}
rayParams.FilterType = Enum.RaycastFilterType.Exclude
local direction = (mousePos - origin).Unit
local cf = CFrame.lookAlong(vector.zero, direction)
cf *= CFrame.Angles(math.rad(Random.new():NextNumber(-spread,spread)), math.rad(Random.new():NextNumber(-spread,spread)), 0) -- rotate by a random amount
local new_direction = cf.LookVector
local maxDistance = 300
local raycastResult = workspace:Raycast(origin, new_direction * maxDistance, rayParams)
if raycastResult then
CreateTracer(origin, raycastResult.Position)
local hitPart = raycastResult.Instance
local model = hitPart:FindFirstAncestorOfClass("Model")
if model and model:FindFirstChild("Humanoid") then
if hitPart.Name == "Head" then
model.Humanoid:TakeDamage(damage*1.5)
else
model.Humanoid:TakeDamage(damage)
end
end
else
CreateTracer(origin, origin + direction * maxDistance)
end
end)
#its making a tracer for every player when i shoot
1 messages · Page 1 of 1 (latest)
local function CreateTracer(startPos, endPos, color)
local tracer = Instance.new("Part")
tracer.Anchored = true
tracer.CanCollide = false
tracer.Material = Enum.Material.Neon
tracer.Color = color or Color3.fromRGB(255, 255, 82)
tracer.Transparency = 0.2
local distance = (endPos - startPos).Magnitude
tracer.Size = Vector3.new(0.1, 0.1, distance)
tracer.CFrame = CFrame.new(startPos, endPos) * CFrame.new(0, 0, -distance / 2)
tracer.Parent = workspace
Debris:AddItem(tracer, 0.05)
end
idk how to fix the bug
wait mb i didnt say it
theres a bug where its when i shoot its making a tracer from every gun that is current being held
use a different shootevent for each fun or better, generate ur gun like gun1 gun2 so on with iteration then just pass the name and get the gun with that name in the server event
so like it won't activate that event u use for all the guns that have that event set up
and use unreliableremoteevent for that bc ur going to shoot rapidly and remotevent have a big overhead so unreliable remote event is better for this