Hi there, this is my second question and this is basically related to my 1st question, but not quite. My first question was a GUI and the GUI only appears to me, but I want all the players to teleport to me. How? Here's the Script that only appears to me.
game.Players.PlayerAdded:connect(function(plr) if plr.Name == "CjGamer1454" then local MoveGui = game.ReplicatedStorage["ScreenGui"]:Clone() MoveGui.Parent = plr.PlayerGui end end)
and here's the Teleport Script.
spawn = game.Workspace.HouseArea -- HouseArea is where all of us will teleport player = script.Parent.Parent.Parent.Parent function onClicked() player.Character:MoveTo(spawn.Position) end script.Parent.MouseButton1Down:connect(onClicked)
So, you want every player in the game to teleport to HouseArea? Also, avoid using the variable name "spawn" as this is the name of a built in Roblox function that creates new threads
local funtcion onClicked() local spawnArea = game.Workspace.HouseArea; local playerList = game.Players:GetChildren; local playerToTeleport = nil; for key, value in pairs(playerList) do playerToTeleport = game.Workspace:FindFirstChild(value.Name); if playerToTeleport ~= nill then player.Torso.CFrame = CFrame.new(spawnArea.Position); end end end
There may be some bugs here, I'm not using studio to verify it. Here is an explanation, 1: Function definition 2: spawnArea is referencing your HouseArea 3: We need to store all the players in your game in a table
5: Loop over all the value in the table we just made 6: Reference an individual player 7: Just in case the player leaves or they were not found we check here 8: Teleport their torso using CFrame (As to avoid killing them)