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

Two raycast questions (Why does first one work and 2nd one doesn't?)

Asked by 5 years ago
Edited 5 years ago

local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300)

shouldn't mouse.Hit.p be nil if it clicks the sky and break the script? (Got this from wiki) I don't understand how ^ works also on that note,

how can I make this work? for reference I'm trying to create a ray to find the distance from the humanoidrootpart to at most 50 studs below the humanoidrootpart

local char = script.Parent.Parent
print(char.Name)
while wait(.1) do 
    local visualization = workspace:FindFirstChild("VisualizationOfFall") or Instance.new("Part") 
    visualization.Name = "VisualizationOfFall" 
    visualization.Parent = workspace
    local distanceToGround = Ray.new(char.HumanoidRootPart.Position, (-char.HumanoidRootPart.Position).unit*-50) 
    local part, position = workspace:FindPartOnRay(distanceToGround, char, false, true)
    local distance = (char.HumanoidRootPart.Position - position).magnitude
    visualization.BrickColor = BrickColor.new("New Yeller")
    visualization.Transparency = .5
    visualization.CanCollide = false
    visualization.Anchored = true
    visualization.Size = Vector3.new(.5,.5,distance)
    visualization.CFrame = CFrame.new(char.HumanoidRootPart.Position - position) * CFrame.new(0,0, -distance/2) 
end

0
That's why you use "if mouse.Target == nil then return end" basicecstasy 122 — 5y
0
This had no relevance to the question, the way it is works no matter what, even if the mouse target is nil ( the sky ), taken straight from the wiki masterblokz 58 — 5y
0
Mouse.Hit.p can never be nil, as it just returns the mouse's position in the game world. Also, at line 7, that makes the ray shoot upwards, since a negative multiplied by a negative returns a positive number, so it's equivalent to Ray.new(char.HumanoidRootPart.Position, char.HumanoidRootPart.Position.unit*50) cringe_worthey 97 — 5y
0
Thanks, but that didn't work either. The part is just in a static place in the workspace. masterblokz 58 — 5y

Answer this question