Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

All Players Teleport?

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

✓ Accepted answer

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)

10 comments

0

Yes sir

0

Give me a second to write an answer.

0

ok thank yoU!

0

Alright, here is my attempted answer.

0

thx men

0

No problem! If it helped you, can you give me rep?

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?

0

Oh nvm I figured it out my bad

0

Sorry, I have no GUI experience

0

There is a problem with line 6

This discussion is preserved as it was. New answers, comments, and votes are closed.