I have been looking for so long and I cant find anyone else who has the same problem
my script:
local tool = script.Parent
local remote = tool:WaitForChild("OnShot")
local debris = game:GetService("Debris")
local TweenService = game:GetService("TweenService")
local function CreateBeam(origin, direction)
local midpoint = origin + direction/2
local part = Instance.new("Part")
part.Parent = workspace
part.Anchored = true
part.CanCollide = false
part.Material = Enum.Material.Neon
part.BrickColor = BrickColor.new("Really red")
part.CFrame = CFrame.new(midpoint, origin)
part.Size = Vector3.new(.5, .5, direction.magnitude)
debris:AddItem(part, 1)
end
remote.OnServerEvent:Connect(function(player, mousePos, originPos)
local direction = (mousePos - originPos).Unit * 300000000000
local result = workspace:Raycast(originPos, direction)
if result then
local character = result.Instance.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid and humanoid ~= player.Character.Humanoid then
humanoid.Health -= 5
end
end
CreateBeam(originPos, direction)
end)
Hmm, try adding this raycast visualizer to your code:
-- for more info on these, check out:
-- https://developer.roblox.com/en-us/api-reference/function/WorldRoot/Raycast
-- https://developer.roblox.com/en-us/api-reference/datatype/RaycastParams
local result = workspace:Raycast(origin, direction, params)
if result then
local distance = (origin - result.Position).Magnitude
local p = Instance.new("Part")
p.Anchored = true
p.CanCollide = false
p.Size = Vector3.new(0.1, 0.1, distance)
p.CFrame = CFrame.lookAt(origin, position)*CFrame.new(0, 0, -distance/2)
end
I’m not super good with raycasts but using this visualizer you should be able to see what’s going on, maybe this will provide clarity to your issue.
There is most likely an issue with the raycast running into an unfiltered-out object in between the origin and destination positions, which could be objects directly near the origin. Use the RaycastParams to apply a table that contains the player’s character (if the origin is a tool that the player is holding) and anything else that you need the raycast to ignore.
i’m having the same issue. I’ve already put raycast parameters to filter the character but it’s still not working. Did putting parameters fix it for you?