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

Teleport script is incorrect?

Asked by 7 years ago

I don't get how it doesn't work, I wanted to make a teleport tool where, where ever you click, you go to

Extra info: btw its a localscript and its in a tool

plr = game.Players.LocalPlayer
mouse = plr:GetMouse()

script.Parent.Activated:connect(function()
    plr.Character.Torso.CFrame = CFrame.new(mouse.Hit, mouse.Hit, mouse.Hit)

end

I thought this would work but it doesn't, it just teleports me to where i spawn in the world when i click it

2 answers

Log in to vote
0
Answered by 7 years ago

What's wrong?

You're using mouse.Hit wrong! And you're not ending your function the correct way!


Mouse.Hit

If you want to set a CFrame you don't do it like so: CFrame.new(mouse.Hit,mouse.Hit,mouse.Hit) because that's the same as saying: Vector3.new(part.Position,part.Position,part.Position) You would only say part2.Position = part.Position. Also, if you're going to do it this way, use Mouse.Hit.p because that would turn 9 values into 3.


Functions

Can be written in many different ways.

function a()
    --code
end

function()
    --code
end

event:connect(function()
    --code
end) --Note how it has a closing parenthesis at the end, that's the close the open parenthesis at the beginning

In the way you're writing it you need a ")" after end.


Final Product

plr = game.Players.LocalPlayer
mouse = plr:GetMouse()

script.Parent.Activated:connect(function()
    plr.Character.Torso.CFrame = mouse.Hit.p
end)


Hope it helps!

0
Also make sure to add 7 to the Y value of mouse.Hit.p so the character doesn't teleport into the ground. TheDeadlyPanther 2460 — 7y
0
Why 7? It would be 2.5, plus it's their script, not mine. EzraNehemiah_TF2 3552 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago


script.Parent.Activated:connect(function(plr) mouse = plr:GetMouse() local tp = player.FindFirstChild("Torso") tp.CFrame = CFrame.new(Vector3.new(mouse.Hit, mouse.Hit, mouse.Hit)) end

That should work better, don't make it a local script. It will find the player, look for their torso, and teleport them. FindFirstChild is a good way for teleportation. It's also shorter than game.Palyer.Localplayer. But if you want it in startergui for what you're doing (because you can't set it to reset gui on spawn if you want), then idk waht to tell ya. Make it a locla script I guess?

Answer this question