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
1 | plr = game.Players.LocalPlayer |
2 | mouse = plr:GetMouse() |
3 |
4 | script.Parent.Activated:connect( function () |
5 | plr.Character.Torso.CFrame = CFrame.new(mouse.Hit, mouse.Hit, mouse.Hit) |
6 |
7 | end |
8 |
9 | I thought this would work but it doesn't, it just teleports me to where i spawn in the world when i click it |
You're using mouse.Hit wrong! And you're not ending your function the correct way!
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.
Can be written in many different ways.
01 | function a() |
02 | --code |
03 | end |
04 |
05 | function () |
06 | --code |
07 | end |
08 |
09 | event:connect( function () |
10 | --code |
11 | 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.
1 | plr = game.Players.LocalPlayer |
2 | mouse = plr:GetMouse() |
3 |
4 | script.Parent.Activated:connect( function () |
5 | plr.Character.Torso.CFrame = mouse.Hit.p |
6 | end ) |
Hope it helps!
1 | script.Parent.Activated:connect( function (plr) |
2 | mouse = plr:GetMouse() |
3 | local tp = player.FindFirstChild( "Torso" ) |
4 |
5 | tp.CFrame = CFrame.new(Vector 3. new(mouse.Hit, mouse.Hit, mouse.Hit)) |
6 |
7 | 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?