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

My script doesnt always raycast, (raycast is nil) how to fix?

Asked by
ym5a 52
3 years ago
local posses = {CFrame.new(-193.704941, 241.69989, -0.480003357, 0.819152057, 0, 0.57357645, 0.24240388, 0.906307757, -0.346188635, -0.519836783, 0.42261827, 0.742403865),CFrame.new(-193.704941, 242.630508, -3.06475449, 0.697058737, 0.340224266, 0.631154895, 0.0641786158, 0.847115993, -0.527518272, -0.714135945, 0.408217907, 0.568654537),CFrame.new(-189.782471, 242.039963, -3.06476402, 0.889660776, -0.150783464, -0.431007892, -0.0293126311, 0.923099697, -0.383441836, 0.455679864, 0.353767157, 0.816825867),CFrame.new(-189.782486, 242.967499, 0.265514374, 0.0578846373, -0.736113608, -0.674378216, -0.00535086077, 0.675272346, -0.737548947, 0.998308778, 0.0463012308, 0.0351490676),CFrame.new(-189.604218, 241.451447, 2.53761482, -0.556839287, -0.618496358, -0.554429054, -0.432180911, 0.785757959, -0.442496479, 0.709329665, -0.00678578019, -0.704843521),CFrame.new(-192.207947, 241.790695, 2.53760529, -0.982462347, -0.170658186, -0.0751157254, -0.156358436, 0.973526359, -0.166726157, 0.101580322, -0.152057409, -0.98313725),CFrame.new(-194.608002, 242.505219, 2.53761292, -0.709329724, 0.00678576529, 0.704843342, -0.156358436, 0.973526359, -0.166726157, -0.687315226, -0.228472382, -0.689490438)}
function moveandShoot(p,cf)
    for i =0,1,0.1 do
        wait()
        p.CFrame = p.CFrame:Lerp(cf,i)
    end
    wait()
    local raycastResult = workspace:Raycast(p.Parent.Origin.Position,p.Parent.Origin.CFrame.LookVector)
    if raycastResult ~= nil then
        print("res")
        print(raycastResult.Position)
        local laser = Instance.new("Part")
        laser.Size = Vector3.new()
    end
end
while true do
    wait(.2)
    moveandShoot(script.Parent.pP,posses[math.random(1,#posses)])
end

It only prints -191.16639709473, 240.19367980957, 0.52220267057419 https://gyazo.com/0e48aacbfd30215061a97acf1dca8a20 Is whats happening please help This is where the location of the position it prints is at: https://gyazo.com/5742907408fe22b3516384bc645e4775 (The Blue dot)

Answer this question