Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Trying to launch a ray from players left arm help?

I'm currently trying to launch 2 different rays. One from the left arm of the characters arm in the -x direction and the on the right arm in the +x direction. I'm just practicing my raycasting I want the rays to print out the name of the objects it touches.


local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait() 
local LeftArm = Character["Left Arm"]
local ray = Ray.new(LeftArm, Vector3(-35,0,0) * 500) 
local hit = workspace:FindPartOnRay(ray, Character)

while true do
	print(hit)
	wait(0.1)
end

So far I just started on the left arm. When I run the game it gives me an error saying attempt to call a table variable on line 6. Not sure what this means as I am pretty new to roblox scripting. If anyone could point me into a direction on how to start actually throwing a ray towards the direction of the left arm and having it print the name of the objects it catches, it would help me a ton. Thanks

1 answer

hit won't always exist in your case, it could be breaking the script, do something like

if hit then
	print(hit)
	wait(0.1)
end

1 comment

0

Okay that stops the error but it seems my ray is not casting.

This discussion is preserved as it was. New answers, comments, and votes are closed.