Hey guys, i’ve been struggling with an issue for quite a while now which is raycasting client-sided. I’ve managed to raycast server-sided but when i transport that code over to the client it refuses to work. I’ve read that raycasting on the client and server should make no difference code wise (apart from referencing and stuff), however i cannot manage to get it working locally. Here is my code:
local function raycast()
local Part = script.Parent
local RayOrigin = Part.Position
local RayDirection = Part.CFrame.LookVector
local RaycastParameters = RaycastParams.new()
RaycastParameters.FilterDescendantsInstances = {Part}
RaycastParameters.FilterType = Enum.RaycastFilterType.Blacklist
local RaycastResult = workspace:Raycast(RayOrigin, RayDirection, RaycastParameters)
print("Raycasted, now waiting for result")
if RaycastResult then
local hitPart = RaycastResult.Instance
print("hit ".. hitPart.Name)
end
end
while wait(1) do
raycast()
end
Nothing is printed, but i’m assuming that’s because for some reason the local script isn’t running (when i put it on the server it prints Raycasted… but not the hitpart). Can anyone enlighten me on why it isn’t running on the client and issues in the code? Thank you!