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

All Players Teleport?

Asked by 9 years ago

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)

1 answer

Log in to vote
1
Answered by 9 years ago

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)

0
Yes sir CjGamer1454 0 — 9y
0
Give me a second to write an answer. DewnOracle 115 — 9y
0
ok thank yoU! CjGamer1454 0 — 9y
0
Alright, here is my attempted answer. DewnOracle 115 — 9y
View all comments (6 more)
0
thx men CjGamer1454 0 — 9y
0
No problem! If it helped you, can you give me rep? DewnOracle 115 — 9y
0
I don't know what a rep is :/ Im new to this site. But it's a GUI if a click it they all teleport. Any idea? CjGamer1454 0 — 9y
0
Oh nvm I figured it out my bad CjGamer1454 0 — 9y
0
Sorry, I have no GUI experience DewnOracle 115 — 9y
0
There is a problem with line 6 CjGamer1454 0 — 9y
Ad

Answer this question