How to get the first value from a table?

I’m making a flag that you can place on the ground, so I’m using raycasting, which returns where the ray collided with the ground, and the direction of the ray, how do I use only that first value?

local tool = script.Parent
local handle = tool:WaitForChild("Handle")

tool.Activated:Connect(function()
	local origin = handle.Position
	local direction = Vector3.new(0,-50,0)
	
	local newRay = Ray.new(origin,direction)
	
end)
1 Like
1 Like

I’m not quite sure what you mean with ‘that first value’, but I am assuming you want to place the flag on the position where the Rayast hit. If so, it is doable by obtaining the .Position of the newRay.


local tool = script.Parent
local handle = tool:WaitForChild("Handle")

tool.Activated:Connect(function()
	local origin = handle.Position
	local direction = Vector3.new(0,-50,0)
	
	local newRay = Ray.new(origin,direction)

	if newRay then --//Check if the ray successfully hit an object. This will result `nil` if it failed, thus not running the code.
		print(ray.Position)
		handle.Position = ray.Position --//Play with these values if not accurate by adding a Vector3.new()
	end
end)
1 Like

I was being an idiot and now i have everything figured out

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.