generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Teleport to mouse click

Previous Thread :: Next Thread 
DaveHereYouTube is not online. DaveHereYouTube
Joined: 13 May 2016
Total Posts: 213
26 Jul 2016 10:19 PM
I've tried making several versions of script to do this. I'm having a hard time finding out if there is a simpler way of doing this.

The idea is you equip this tool. When you click on the screen your character teleports to that location. If you click in the sky it does nothing.

Here's an example of what I've tried. If there's a simpler way please lead me in that direction. Thanks!

Teleport = script.Parent
player = script.Parent.Parent.Parent
playerMouse = game.Players.LocalPlayer:GetMouse()

Teleport.Equipped:connect(function(eventMouse)
eventMouse.Button1Down:connect(function()
print("X: "..playerMouse.X..", Y: "..playerMouse.Y)
print(player)
script.Parent.Parent.Torso.CFrame = CFrame.new(Vector3.new(playerMouse.X,playerMouse.Y,10))
end)
end)
Report Abuse
peIicans is not online. peIicans
Joined: 02 Nov 2013
Total Posts: 1148
26 Jul 2016 10:29 PM
make sure it's localscript

Teleport = script.Parent
player = game.Players.LocalPlayer
playerMouse = player:GetMouse()
char = player.CharactedAdded:wait()

Teleport.Equipped:connect(function(eventMouse)
eventMouse.Button1Down:connect(function()
char:MoveTo(playerMouse.Hit.p)
end)
end)


Report Abuse
DaveHereYouTube is not online. DaveHereYouTube
Joined: 13 May 2016
Total Posts: 213
26 Jul 2016 10:49 PM
That's exactly what I needed. Only thing I had to change was

char = player.CharactedAdded:wait()
should be
char = player.CharacterAdded:wait()

Thank you so much. The next thing I need to work on is a limitation of how far you can click. Such as 100 studs. I'll work on it for a bit but if someone has a suggestion I'd appreciate it.

Thanks again pelicans!
Report Abuse
DaveHereYouTube is not online. DaveHereYouTube
Joined: 13 May 2016
Total Posts: 213
27 Jul 2016 02:50 PM
So to resolve the distance issue I was thinking of doing something like this.

playerxyz = playerMouse.Hit.p

I want to get 3 variables out of playerMouse.Hit.p and save them into an x, y, z variable. Once I do that I can use them to find out if the place that you click is within 100 studs of the player. How do I save playerMouse.Hit.p into 3 different x y z variables?
Report Abuse
DaveHereYouTube is not online. DaveHereYouTube
Joined: 13 May 2016
Total Posts: 213
27 Jul 2016 08:40 PM
bump
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image