Unable to cast vector2 to float

Hello! I scripted this thing for touch tapinworld. The idea is to get the lookvector of the players tap. But it returns unable to cast vector2 to float. I have no idea what the problem is. Can someone help me please?

uis.TouchTapInWorld:Connect(function(pos, proccesed)
	if not proccesed and equiped == true then
		if db == false then
			db = true
			local camera = workspace.CurrentCamera

			-- Get the position where the touch occurred
			local touchPosition = pos
			print(pos)

			-- Use ViewportPointToRay to cast a ray from the touch position into the world
			local ray = camera:ViewportPointToRay(touchPosition)

			-- Now you can use the ray for various purposes, such as detecting hits with parts in the world
			local hitPart, hitPosition = workspace:FindPartOnRay(ray, nil, false, true)
			
			local vector = mouse.Hit.LookVector
			local speed = script.Parent.Speed.Value
			local Reload = script.Parent.ReloadTime.Value
			if hitPosition then
				local lookVectorAtHit = (hitPosition - camera.CFrame.Position).Unit
				vector = lookVectorAtHit

			end
			anim:Play()
			script.Parent.throwsfx:Play()
			wait(0.3)
			script.Parent.Handle.Transparency = 1
			script.Parent.Throw:FireServer(vector)
			wait(Reload-0.3)
			script.Parent.Handle.Transparency = 0
			db = false
		end

	end
end)
1 Like

Try camera:ViewportPointToRay(touchPosition.X,touchPosition.Y,250)
You have to put the x,y, and depth (how far you want the ray to go) separately instead of passing the Vector2.

No way!! Finally you fixed my problem. I was searching everywhere and it works now. Thank you so much!!! God bless :pray:

1 Like

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