Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Teleporting with x y z coordinates?

Asked by 5 years ago

Alright, I've done a script that makes me know my cursor coordinates. What if I want to teleport there? I tried to do something like this, but it's not working.

local m = game.Players.LocalPlayer:GetMouse()
local character = game.Players.LocalPlayer.Character
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local MouseCFrame = Mouse.Hit
local MousePosition = MouseCFrame.p
local db = true
local secondtime = false

m.KeyDown:connect(function(k)
k = k:lower()
if k == 'x' then
  game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(MousePosition))

end
end)

Help please.

1 answer

Log in to vote
0
Answered by
oftenz 367 Moderation Voter
5 years ago
Edited 5 years ago

You can raycast using the player's mouse's position - Camera.ScreenPointToRay

A more simpler way of doing this,however is using Mouse.Hit

target = game.Players.LocalPlayer:GetMouse() .Hit
x = target.X
y = target.Y
z = target.Z
game.Players.LocalPlayer.Character:MoveTo(Vector3.new(x,y,z))

This can work fine, but I would recommend the ScreenPointToRay.

0
Yeah, I honestly don't know how to use it. May you explain me how to write it in a LocalScript? Fixer1987 95 — 5y
0
Hey I found a more simpler way of doing this. oftenz 367 — 5y
0
Check the update. oftenz 367 — 5y
0
Checking if it works. Fixer1987 95 — 5y
0
It works, thanks! Fixer1987 95 — 5y
Ad

Answer this question