You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to raycast normally.
What is the issue? Include screenshots / videos if possible!
It returns nil
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve copied youtubers’ code and it still doesn’t do anything at all
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local part = script.Parent
local origin = part.Position
local direction = part.CFrame.LookVector * 10
local raycastResult = workspace:Raycast(origin, direction) -- returns nil
if raycastResult then
print(raycastResult.Instance)
else
print("WTH DUDE")
end
After many failures I decided to look up tutorials but it didn’t help me, so thank you in advance if you can help me
local part = workspace.part
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {part}
raycastParams.IgnoreWater = true
local origin = part.Position
local direction = part.CFrame.LookVector * 10
local raycastResult = workspace:Raycast(origin, (direction - origin).Unit * 1000, raycastParams)
if raycastResult then
print("hit")
else
print("not hit")
end
Wrote this for you, try something like this.
–EDIT2–
Fixed params because I pasted them from something else, and made the script easier to read.
I tried something like this, if I remove everything inside the blacklist, it works, Otherwise it will still be nil
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {workspace.Baseplate}
raycastParams.IgnoreWater = true
local part = script.Parent
local origin = part.Position
local direction = part.CFrame.LookVector * 10
local raycastResult = workspace:Raycast(origin, (direction - origin).Unit * 1000, raycastParams)
if raycastResult then
print("hit")
else
print("not hit")
end
like this for example, I added baseplate but it still prints not hit. But when I remove it, it prints “hit”
local part = script.Parent
game:GetService("RunService"):Connect(function()
local origin = part.Position
local direction = part.CFrame.LookVector * 10
local raycastResult = workspace:Raycast(origin, direction) -- returns nil
if raycastResult then
print(raycastResult.Instance)
else
print("WTH DUDE")
end
end)
local origin = part.Position
local direction = part.CFrame.LookVector * 10
local raycastResult = workspace:Raycast(origin, (origin - workspace.CollidePart.Position).Unit * 1000, raycastParams)
if raycastResult then
print("hit")
print(raycastResult.Instance)
else --......
No, RunService can be used in both server and client. The only event that fires on the client is RenderStepped, while Stepped and Heartbeat can be used in both.