Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Part from FindPartOnRay returning the position?

Asked by 7 years ago

It works okay except the part value is returned as the position

LocalScript:

local tool = script.Parent
local player = game:GetService("Players").LocalPlayer

tool.Equipped:connect(function(mouse)

    mouse.Button1Down:connect(function()
        local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p + Vector3.new(math.random(-1.5,1.5),math.random(-1.5,1.5),math.random(-1.5,1.5))).unit * 300)
        local partHit, positionHit = workspace:FindPartOnRay(ray, player.Character, false, true)

        local distance = (tool.Handle.CFrame.p - positionHit).magnitude
            script.Parent.FireLaser:FireServer(positionHit,distance,partHit)

    end)
end)

Server Script:

tool = script.Parent




function Laser(player,positionHit,distanceHit)
            local beam = Instance.new("Part", workspace)
        beam.BrickColor = BrickColor.new("Bright red")
        beam.FormFactor = "Custom"
        beam.Material = "Neon"
        beam.Transparency = 0.25
        beam.Anchored = true
        beam.Locked = true
        beam.CanCollide = false


        beam.Size = Vector3.new(0.3, 0.3, distanceHit)
        beam.CFrame = CFrame.new(tool.Handle.CFrame.p, positionHit) * CFrame.new(0, 0, -distanceHit / 2)

        game:GetService("Debris"):AddItem(beam, 0.1)
end

function DMGPlayer(player,part)
    print(part)
    end


script.Parent.FireLaser.OnServerEvent:connect(Laser)
script.Parent.FireLaser.OnServerEvent:connect(DMGPlayer)

0
Can you say precisely where the problem is? Try printing out both 'partHit' and 'positionHit' just after the ray cast and see what they come out as. duckwit 1404 — 7y
0
partHit comes out as a Vector3 and positionHit is one number... xXRealFurryKittenXx 20 — 7y

Answer this question