debounce = false
script.Parent.EquipHandler.OnServerEvent:Connect(function()
tool["Gun equip "]:play()
end)
local function shoot(player, origin, direction)
if debounce then
print ("bro debounced")
else
debounce = true
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.IgnoreWater = true
local function createBulletVisualization(origin, direction)
local bullet = Instance.new("Part")
bullet.Size = Vector3.new(0.2, 0.2, 5)
bullet.CFrame = CFrame.new(origin, origin + direction) * CFrame.new(0, 0, -2.5)
bullet.CanCollide = false
bullet.Material = Enum.Material.Neon
bullet.BrickColor = BrickColor.new("Bright yellow")
bullet.Parent = workspace
local tweenService = game:GetService("TweenService")
local bulletTween = tweenService:Create(
bullet,
TweenInfo.new(0.1),
{Position = origin + (direction * 500)}
)
bulletTween:Play()
tool["Gun Shot"]:Play()
-- Destroy the bullet after the tween finishes
bulletTween.Completed:Connect(function()
bullet:Destroy()
end)
end```
#How do I add tracers to raycasts?
9 messages · Page 1 of 1 (latest)
createBulletVisualization(origin, direction)
task.wait(0.25)
debounce = false
local raycastResult = workspace:Raycast(origin, direction * 500, raycastParams)
if raycastResult then
local hitPart = raycastResult.Instance
local hitPosition = raycastResult.Position
local character = hitPart:FindFirstAncestorWhichIsA("Model")
local humanoid = character and character:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(25)
else
print("Hit something else:", hitPart.Name)
end
--local bulletHole = Instance.new("Part")
--bulletHole.Size = Vector3.new(0.2, 0.2, 0.2)
--bulletHole.Position = hitPosition
--bulletHole.Anchored = true
--bulletHole.CanCollide = false
--bulletHole.BrickColor = BrickColor.new("Black")
--bulletHole.Parent = workspace
--task.delay(2, function() bulletHole:Destroy() end) -- Destroy after 2 seconds
else
print("Raycast didnt hit anything")
end
end
end
-- Connect the RemoteEvent to the shooting function
remoteEvent.OnServerEvent:Connect(function(player, origin, direction)
shoot(player, origin, direction)
end)
thats the server script
raycast works
bullet dosent
what part of the bullet doesnt work
also keep in mind for tweening your bullet that if you use a flat 0.1 tween time the bullets speed will appear to vary based on distance
since speed = distance / time, keeping time constant while distance varies would make speed different. this could be fixed by adjusting the time of the tween depending on the distance
nah it works now