I have a game, and I am currently working on selecting a random minigame. I already have the randomizer, and a textlabel already says what minigame it will be. Each minigame is a model. Each model has a part. I’m trying to teleport all players to THAT part, the one that was chosen. Here’s an image:
So if the randomizer selected let’s say Spinner, then I want all players to be teleported to the part UNDER the model for Spinner. By the way, I am firing a remoteevent, since the randomizer is on a Server Script, and then I’m making the text change for all clients in a localscript.
You Can Try Do Something Like This
" local char = player.Character
local humanoidrootpart = char.HumanoidRootPart
for i, v in paris(game.Get Your Folder Name:GetPlayers()
v.HumanoidRootPart = CFrame(x,y,z) "
Or Something Like That!
I’ll try that right away. (30char)
''''
local parts = {} -- put all the parts here
for _, player in pairs(game.Players:GetPlayers()) do
local chosen = math.random(1, #parts)
player.Character.CFrame = chosen.CFrame
end
'''
Let me know if there are errors
I can’t put the parts into a table, i had to use GetChildren(), and there were no errors, and it did not work.
This is functional and tested
local part = workspace.Part
for _,player in pairs(game:GetService("Players"):GetPlayers())do
if player and player.Character then
player.Character:MoveTo(part.Position)
end
end
Simply loop through the players, and teleport them.
You can use SetPrimaryPartCFrame.
ipairs
is used for arrays, GetPlayers()
returns an array, hence:
local Players = game:GetService('Players')
local Targets = Players:GetPlayers() -- Assigning it as a local is faster.
for _, Player in ipairs(Targets) do
-- Teleport them
end
It only worked once…? (30char)
Ok, I think I need to explain a bit more. I’m making minigames, and a part is assigned to each model for a minigame. I’m trying to make all the players teleport to the correct part that is the child of the chosen minigame.
What you want to do is iterate through all of the players and teleport them to the desired part.
local Players = game:GetService("Players")
function teleportAllPlayers(part) -- part being the part you want to TP them to.
for _,v in pairs(Players:GetChildren()) do -- Go through all the players in-game.
local character = v.Character -- Find their character model.
if character then
local humanoidRootPart = character.HumanoidRootPart -- Find their HumanoidRootPart
if humanoidRootPart then
humanoidRootPart.CFrame = part.CFrame -- Teleport them!
end
end
end
end
Use this function in your code to send all your players to the desired location!
Hope this helps out.
Testing it out now, thanks! (30char)
I would go about this by having a series of maps, and inside of the Models you have a folder called SpawnLocations. SpawnLocations contains a bunch of parts that you want to player to spawn at.
To select one of these random maps, you can follow this code:
local selectedMap = game.ReplicatedStorage.Maps:GetChildren()[math.random(1,#game.ReplicatedStorage.Maps:GetChildren())]:Clone()
selectedMap.Parent = workspace
local part = workspace.Part
for _,player in pairs(game:GetService("Players"):GetPlayers())do
if player and player.Character then
local selectedLocation = selectedMap.SpawnLocations:GetChildren()[math.random(1,#selectedMap.SpawnLocations:GetChildren())]
player.Character:MoveTo(selectedLocation.Position)
end
end
didnt work… (30charrrrrrrrrrrr)
Could you be a bit more specific? What did the output say? How are you using it?
local parts = {workspace.Part, e.t.c.}
You have to add the parts like that
I think you’re expecting me to write all your code out for you? What I’ve given you isn’t an entire code base for a minigame. Be more specific of what your problem is.
Why did you mentioned this now? Wouldn’t it be helpful if you put this in your first post?
Also you could just edit your first post instead of writing another one.
Sorry… (30characterssss)
No worries. You should search up other posts if you need help.
I am still unsure of what your issue is. What I’ve given you should work as is.