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: Player.Character:MoveTo

Previous Thread :: Next Thread 
Qerzo is not online. Qerzo
Joined: 05 Dec 2015
Total Posts: 17
13 Sep 2016 01:39 PM
Is there a way I can make this move the character to random spawn locations on the map?
Report Abuse
Skelris is not online. Skelris
Joined: 02 Jan 2009
Total Posts: 4785
13 Sep 2016 01:40 PM
Yes.
Report Abuse
Mr_Gibus is not online. Mr_Gibus
Joined: 17 Jun 2012
Total Posts: 368
13 Sep 2016 01:40 PM
Step 1: Get the Spawn in a list.

Step 2: Chose a Spawn from that list.

Step 3: CFrame the HumanoidRootPart of the player to the Spawns Position

Step 4: Done.
Report Abuse
Qerzo is not online. Qerzo
Joined: 05 Dec 2015
Total Posts: 17
13 Sep 2016 01:43 PM
@Mr_Gibus here is my script, I just started out, can you please help me how I can make it x3

Player = game.Players.LocalPlayer
MPS = game.Workspace.SpawnLocation
BlackScreen = script.Parent.BlackScreen
TeleportButton = script.Parent.TeleportButton
Status = script.Parent.BlackScreen.Status
HasPressedTeleport = false

function MouseEnterTeleportButton()
TeleportButton.FontSize = "Size28"
TeleportButton.BackgroundColor3 = Color3.new(255, 1, 1)

end

function MouseLeftTeleportButton()
TeleportButton.FontSize = "Size24"
TeleportButton.BackgroundColor3 = Color3.new(1, 1, 1)

end

function TeleportPlayer()
if HasPressedTeleport == false then
Player.Character:MoveTo(MPS.Position)
end
end

TeleportButton.MouseEnter:connect(MouseEnterTeleportButton)
TeleportButton.MouseLeave:connect(MouseLeftTeleportButton)
TeleportButton.MouseButton1Down:connect(TeleportPlayer)
Report Abuse
ManxFox is not online. ManxFox
Joined: 12 Nov 2008
Total Posts: 227
13 Sep 2016 01:44 PM
first you need a group with all the spawn locations in that you can get to, so make a group with those spawn locations in.

Next, in a script you need to find the pathway to those spawns

so the script would look something like this so far:

local spawns = game.Workspace:findFirstChild("spawnGroupName",true):GetChildren()

next, you need a for loop that moves all players character to a random spawns position:

for i,v in pairs (game.Players:GetChildren()) do
v.Character:MoveTo(spawns[math.random(1,#spawns)].Position)
end

then put it into a function that you can call whenever you need it later on in the script:

local spawns = game.Workspace:findFirstChild("spawnGroupName",true):GetChildren()

function randomPlayerSpawning()

for i,v in pairs (game.Players:GetChildren()) do
v.Character:MoveTo(spawns[math.random(1,#spawns)].Position)
end
end

that is your finished script ^


Report Abuse
Qerzo is not online. Qerzo
Joined: 05 Dec 2015
Total Posts: 17
13 Sep 2016 01:52 PM
@ManxFox thanks for your help, but am I doing something wrong here?

Player = game.Players.LocalPlayer
MPS = game.Workspace.SpawnLocation
BlackScreen = script.Parent.BlackScreen
TeleportButton = script.Parent.TeleportButton
Status = script.Parent.BlackScreen.Status
HasPressedTeleport = false
local spawns = game.Workspace:findFirstChild("MPS",true):GetChildren()

function MouseEnterTeleportButton()
TeleportButton.FontSize = "Size28"
TeleportButton.BackgroundColor3 = Color3.new(255, 1, 1)

end

function MouseLeftTeleportButton()
TeleportButton.FontSize = "Size24"
TeleportButton.BackgroundColor3 = Color3.new(1, 1, 1)

end

function TeleportPlayer() -- Here is the updated part with your script
if HasPressedTeleport == false then
for i,v in pairs (game.Players:GetChildren()) do
v.Character:MoveTo(spawns[math.random(1,#spawns)].Position)
end
end

end

TeleportButton.MouseEnter:connect(MouseEnterTeleportButton)
TeleportButton.MouseLeave:connect(MouseLeftTeleportButton)
TeleportButton.MouseButton1Down:connect(TeleportPlayer)
Report Abuse
ManxFox is not online. ManxFox
Joined: 12 Nov 2008
Total Posts: 227
13 Sep 2016 02:01 PM
your spawns variable already has a variable for it :P so you may as well make it:

local spawns = MPS:GetChildren()

you also might want to consider changing your other variables:
Player (line 1)
MPS (line 2)
BlackScreen (line 3)
TeleportButton (line 4)
Status (line 5)
HasPressedTeleport (line 6)

to local variables much like the spawns (just put local behind their names)

the for loop/if statement looks about right

when you're calling the teleport function

you might want to use MouseButton1Click instead of MouseButton1Down so if you accidentally click down on it it won't fire the function by accident

other than that is should be working fine. if that doesn't work let me know



Report Abuse
Qerzo is not online. Qerzo
Joined: 05 Dec 2015
Total Posts: 17
13 Sep 2016 02:08 PM
@ManxFox, I don't know what you mean by changing the other variables?
Report Abuse
ManxFox is not online. ManxFox
Joined: 12 Nov 2008
Total Posts: 227
13 Sep 2016 02:13 PM
right now you're assigning variables just as they are, for example:

MPS = game.Workspace.SpawnLocation

MPS is the variables name

= defines the end of the variables name

game.Workspace.SpawnLocation is the actual place or thing the variable is referring to

you can assign the variable as a local variable and in most scripts this allows the script to access it quicker. so what you would want is:

local MPS = game.Workspace.SpawnLocation



now, on another note, I realised your MPS is only a single spawn point.

are you wanting the character to teleport just to that specific spawn or are you wanting them to teleport to a random spawn in a group of spawns?


another little question, is the script this is all wrote in a LocalScript?


Report Abuse
thinkablejokester is not online. thinkablejokester
Joined: 23 Nov 2011
Total Posts: 2444
13 Sep 2016 02:16 PM
@Manx sorry I'm switching from my brothers account, but I want to teleport the character to a random spawn in a group of spawns I just made the group called SpawnLocation
Report Abuse
ManxFox is not online. ManxFox
Joined: 12 Nov 2008
Total Posts: 227
13 Sep 2016 02:19 PM
Okay, is the script a LocalScript or a normal Script?


Report Abuse
thinkablejokester is not online. thinkablejokester
Joined: 23 Nov 2011
Total Posts: 2444
13 Sep 2016 02:19 PM
@Manx yes I made the script a local script.
Report Abuse
ManxFox is not online. ManxFox
Joined: 12 Nov 2008
Total Posts: 227
13 Sep 2016 02:25 PM
########################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
Report Abuse
thinkablejokester is not online. thinkablejokester
Joined: 23 Nov 2011
Total Posts: 2444
13 Sep 2016 02:25 PM
Here is how my script is atm

Player = game.Players.LocalPlayer
MPS = game.Workspace.SpawnLocation
local spawns = MPS.GetChildren()
TeleportButton = script.Parent.TeleportButton
Status = script.Parent.BlackScreen.Status
PressedButton = false

function MouseEnterTeleportButton()
TeleportButton.FontSize = "Size28"
TeleportButton.BackgroundColor3 = Color3.new(255, 1, 1)

end

function MouseLeftTeleportButton()
TeleportButton.FontSize = "Size24"
TeleportButton.BackgroundColor3 = Color3.new(1, 1, 1)

end

function TeleportPlayer()
wait(0.5)
if PressedButton == false then
for i,v in pairs (game.Players:GetChildren()) do
v.Character:MoveTo(spawns[math.random(1,#spawns)].Position)

end
end

end

TeleportButton.MouseEnter:connect(MouseEnterTeleportButton)
TeleportButton.MouseLeave:connect(MouseLeftTeleportButton)
TeleportButton.MouseButton1Down:connect(TeleportPlayer)
Report Abuse
ManxFox is not online. ManxFox
Joined: 12 Nov 2008
Total Posts: 227
13 Sep 2016 02:25 PM
it should be working fine then?


Report Abuse
thinkablejokester is not online. thinkablejokester
Joined: 23 Nov 2011
Total Posts: 2444
13 Sep 2016 02:27 PM
I don't know why but it doesn't work. Does it have to do with the fact that I'm testing this in Studio?
Report Abuse
ManxFox is not online. ManxFox
Joined: 12 Nov 2008
Total Posts: 227
13 Sep 2016 02:28 PM
Here, just try this:

local Player = game.Players.LocalPlayer
local MPS = game.Workspace.SpawnLocation
local spawns = MPS.GetChildren()
local TeleportButton = script.Parent.TeleportButton
local Status = script.Parent.BlackScreen.Status

function MouseEnterTeleportButton()
TeleportButton.FontSize = "Size28"
TeleportButton.BackgroundColor3 = Color3.new(255/255, 1/255, 1/255)
end

function MouseLeftTeleportButton()
TeleportButton.FontSize = "Size24"
TeleportButton.BackgroundColor3 = Color3.new(1/255, 1/255, 1/255)
end

function TeleportPlayer()
wait(0.5)
for i,v in pairs (game.Players:GetChildren()) do
v.Character:MoveTo(spawns[math.random(1,#spawns)].Position)
end
end

TeleportButton.MouseEnter:connect(MouseEnterTeleportButton)
TeleportButton.MouseLeave:connect(MouseLeftTeleportButton)
TeleportButton.MouseButton1Down:connect(TeleportPlayer)


Report Abuse
thinkablejokester is not online. thinkablejokester
Joined: 23 Nov 2011
Total Posts: 2444
13 Sep 2016 02:31 PM
@Manx still no dice, I really don't understand :/
Report Abuse
ManxFox is not online. ManxFox
Joined: 12 Nov 2008
Total Posts: 227
13 Sep 2016 02:31 PM
if you,d like, you can add me and set up a teamcreate, I'll come join and look at it myself?


Report Abuse
thinkablejokester is not online. thinkablejokester
Joined: 23 Nov 2011
Total Posts: 2444
13 Sep 2016 02:37 PM
@Manx sure, I've never used it before so idk how to set up.
Report Abuse
ManxFox is not online. ManxFox
Joined: 12 Nov 2008
Total Posts: 227
13 Sep 2016 02:39 PM
Studio > View > TeamCreate > Turn On


Report Abuse
thinkablejokester is not online. thinkablejokester
Joined: 23 Nov 2011
Total Posts: 2444
13 Sep 2016 02:40 PM
Alright turned it on
Report Abuse
ManxFox is not online. ManxFox
Joined: 12 Nov 2008
Total Posts: 227
13 Sep 2016 02:42 PM
you have to invite me into it, there should be a box you can type my name into


Report Abuse
thinkablejokester is not online. thinkablejokester
Joined: 23 Nov 2011
Total Posts: 2444
13 Sep 2016 02:42 PM
######################################################
Report Abuse
thinkablejokester is not online. thinkablejokester
Joined: 23 Nov 2011
Total Posts: 2444
13 Sep 2016 02:43 PM
I invited you, sorry about the hashtags I wanted to send a screenshot
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