script.Parent.Fire.OnServerEvent:Connect(function(player,mousePos)
script.Parent.Handle.Sound:Play()
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(script.Parent.Handle.Position,(mousePos - script.Parent.Handle.Position)*200,raycastParams)
if raycastResult then
local hitpart = raycastResult.Instance
local model = hitpart:FindFirstAncestorOfClass("Model")
if model then
if model:FindFirstChild("Humanoid") then
model.Humanoid.Health -= 20
local part = Instance.new("Part")
part.Transparency = 1
part.CanCollide = false
part.Parent = model
local smoke = Instance.new("Smoke")
smoke.Color = Color3.new(0.588235, 0.0431373, 0.0431373)
smoke.Parent = part
part.Position = hitpart.Position
smoke.Opacity = 0.2
end
end
end
end)
I have tried many methods from other posts and i cant seem to find out how. I am very confused.
Also, to get the distance between 2 objects you must do (eye - target)
You did the opposite:
local raycastResult = workspace:Raycast(script.Parent.Handle.Position,(mousePos - script.Parent.Handle.Position)*200,raycastParams)
mousePos is the target and the Handle’s position is the eye (where the raycast is coming from) so instead you should swap it to local raycastResult = workspace:Raycast(script.Parent.Handle.Position,(script.Parent.Handle.Position - mousePos)*200,raycastParams)
Now, to make a raycast visible you will need to crrate a part like so:
local Part = Instance.new("Part", game.Workspace)
Part.Name == "Part"
Part.Size = Vector3.new(4, 4, distance) -- changed the size of the part to the magnitude of the distance
Part.CFrame = CFrame.new(script.Parent.Handle.Position, distance) * CFrame.new(0, 0, -distance/2) -- makes so that the back of the part is where the origin supposed to be