I already detected when the mouse is 50 studs away from the player but I wanna make the character move 50 studs where the mouse is IF the mouse is to far away
Do you want to teleport the player by a factor of 50 studs? If so, you can cast a ray from the player’s character to the mouse’s position and make the ray 50 studs long. If the ray intercepts a part, then the player gets teleported to the intersection point. If the ray doesn’t intercept a part, then the player is teleported 50 studs away.
--Creates a raycast starting at the players upper torso and pointing at the mouse
local rayDirection = (mouse.Hit.p - character.UpperTorso).Unit
local raycastResult = workspace:Raycast(character.UpperTorso,rayDirection * 50,RaycastParams.new())
local hitPosition
--Determines hit position based on raycast's result
if raycastResult then
hitPosition = raycastResult.Position
else
hitPosition = character.UpperTorso.Position + (rayDirection * 50)
end
--Now teleport your character to hitPosition