I’m trying to raycast to character and attach part to character, but when I click to place, it just doesn’t detect any part…
How can I fix this?
game:GetService("UserInputService").InputBegan:Connect(function(input, inChat)
if input.UserInputType == Enum.UserInputType.MouseButton1 and tool.Parent:IsA("Model") then
if placing == false then --turn place mode on, display where it will place using raycast
print("place")
placing = true
while placing == true do
local camPos = workspace.CurrentCamera.CFrame.Position
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local rayResult = workspace:Raycast(camPos, CFrame.new(camPos, mouse.Hit.p).LookVector * ((camPos - mouse.Hit.p).magnitude + 0.01), ray)
if rayResult then --this one works
hologram.CFrame = CFrame.new(rayResult.Position, rayResult.Position + rayResult.Normal) * CFrame.Angles(math.rad(-90), 0, 0)
hologram.Parent = workspace
else
hologram.Parent = nil
end
game:GetService("RunService").Heartbeat:Wait()
end
else --place
--these lines are exactly same
local camPos = workspace.CurrentCamera.CFrame.Position
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local rayResult = workspace:Raycast(camPos, CFrame.new(camPos, mouse.Hit.p).LookVector * ((camPos - mouse.Hit.p).magnitude + 0.01), ray)
print(rayResult) --nil
if rayResult then
print("done") --yes this line never prints
placing = false
end
end
end
end)