#Im guessing im doing this COMPLETELY wrong, but how would i do this correctly

161 messages · Page 1 of 1 (latest)

lyric geyser
#
task.wait(1)

local Positions = {
    Vector3.new(0,0,0)}

for i, pos in pairs(Positions) do
    print(#Positions)
end

local players = game.Players:GetPlayers()

for i = 1, #players, #Positions do
    players[i].Character.HumanoidRootPart.Position = Positions[i]
end
#

i want it to go through the list of all the players and go through all the list of the positions

#

set the first player in the lists position to the first position in the position table

#

and so on

#

but i honestly got like no clue how to do this

bold vault
#

like set their position to the first position

#

?

#

oh wait i see

lyric geyser
#

like set the first players position to the first position

bold vault
#

and second player to the second position?

lyric geyser
#

yes

bold vault
#

and so on

lyric geyser
#

yep

#

for my main menu

bold vault
#

is this client or server

lyric geyser
#

server sided

bold vault
#

alr

#

ima expiriment around in studio to see if a i cant get it work

#

ing

lyric geyser
#

ight

#

also the first for loop in that script is completely useless lol just was testing smth

bold vault
#

what is the purpose of the task.wait(1)?

#

alr

lyric geyser
#

it was when i was testing something else

#

i should prob remove that

#
local Positions = {
    Vector3.new(0,0,0)}

local players = game.Players:GetPlayers()

for i = 1, #players, #Positions do
    players[i].Character.HumanoidRootPart.Position = Positions[i]
end
#

so yea this is what im working w rn

#

ServerScriptService.Positions:13: attempt to index nil with 'HumanoidRootPart'

and this is an error im currently getting

bold vault
#

when does this code run?

#

the second the game starts?

#

or when a player joins

lyric geyser
#

preferrably when the game starts

#

i atleast think

bold vault
#

ill just put it in a function

lyric geyser
#

ok

bold vault
#

so you can use it whenever

lyric geyser
#

im pretty new to scripting

#

so its kinda confusing to me

bold vault
#

yeah dont worry i got you

lyric geyser
#

👍

#

btw how do you detect the second the game starts?

#

do you just detect when a aplayer is added or something

bold vault
#

the game starts the second the first player is added

lyric geyser
#

ok

bold vault
#

any code on the server that isnt in functions or waits will run instantly

#

because the server loads before the client

lyric geyser
#

yea

#

so would we have to put this in a function

bold vault
#

well if you keep it out of a function then it would just run instantly

#

before the player joins

lyric geyser
#

ooh

#

alright

#

so we will put it under a game.players.playeradded:connect(function() ?

#

or a function

#

then connect it to game.players.playeradded

#

below it

bold vault
#

problem with doing that is whenever a player is added it will run

#

so if a player joins when there is already 5 others in the game it will run

lyric geyser
#

so what if you just put a wait for a few seconds before the script is ran

bold vault
#

pretty much think of .ChildAdded()

#

its tricky cause if the first player joining has trash internet it can take alot longer than a few seconds

lyric geyser
#

thats true

#

dont we want the script to run though every time someone new is added so then it adds them to like the third position, and so o

#

on

bold vault
#

ima see if there isnt a event that detects when the game is started

#

cuz there is one when it closes

lyric geyser
#

alright

#

@bold vault if there isnt, I actually do have like a 10 second cutscene at the beginning for everyone every time they join

austere willowBOT
#

studio** You are now Level 4! **studio

lyric geyser
#

Is waiting like 10 seconds enough

#

For horrible internet

bold vault
#

people have worse

#

never try and guess with clients

lyric geyser
#

Ok that’s true lmao

#

Why couldn’t we just detect when a player is added

#

Would that mess up the loop

bold vault
#

i made a little function whenver a player is added

#

it loops through players

#

and if there is more than one it doesnt do anything

#

but if there is only one then proceeds to positioning them

lyric geyser
#

So I want it where if there is a second person that joins the game, the second position gets tooken by that player and so on

So would the function player added not work

bold vault
#

Oh alr

#

i thought you only wanted it for the first person

#

we would want that to be client based then

lyric geyser
#

Ohh ok , yea I want everyone

lyric geyser
bold vault
#

OH

lyric geyser
#

Not only being able to see yourself in the position

#

And the others can see themselves

#

Actually thay may be better possibly, but is that even possible to locally position someone ?

bold vault
#

yes since the player data and position is sent back to the server autmaticly through the network replicator

#

so i think it would work on the client

#

because how roblox is structured is each client is a different game on their computer

#

but the server handles all these different players

lyric geyser
#

Yea

bold vault
#

and your right for thinking that it wouldnt replicate to the server

#

but alot of things like player position and size and stuff replicates to the server without the use of remote events

lyric geyser
#

So to do this it would have to be on a local script ?

bold vault
#

you can do it on the server but it would be extremely complicated

#

thats why i say we do it on the client

lyric geyser
#

Alrigjt

#

And your thinking the same concept as me right ?

bold vault
#

i think lol

lyric geyser
#

Lol

#

wait can you maybe explain what you think I want to happen

#

Idek if we’re on the same track right now

bold vault
#

alright

#

whenever a player joins you want to get the list of players using Players:GetPlayers(), then you want that players index inside of the table it returns to be equal to the same index inside of the position table

lyric geyser
#

Yes

bold vault
#

alr

#

lemme get coding then

lyric geyser
#

Alright

#

And let’s just say thsi for example

#

There is 8 positions in the table (which means 8 people can be in a lobby max)

#

Also btw if I’m being confusing, we have it where they cannot move around

#

And the camera is locked to a part

bold vault
#

alr

#

actually you have to replace the vectors with cframes

#

same numbers

#

alright its working

#
-- Services
local Players = game:GetService("Players")

-- Tables
local CFramesTable = {
    CFrame.new(10, 1000, 10), -- 1st cframe
    CFrame.new(0, 0, 0), -- 2nd cframe and so on
}

-- Player Varibles
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

-- Funcs
local function PositionLocalPlayer()
    for Number, PlayerInPlayers in pairs(Players:GetPlayers()) do
        if Player == PlayerInPlayers then
            HumanoidRootPart.CFrame = CFramesTable[Number]
        end
    end
end

PositionLocalPlayer()
#

here ya go

lyric geyser
#

that works?

bold vault
#

actually lemme do a test with 2 players rq

#

to make sure it works

lyric geyser
#

ok

#

well thank you for the help lol

#

i understand alot more about some stuff as well

#

@bold vault also did you purposely not put it in a playeradded function

bold vault
#

playeradded doesnt work on client i dont think

#

want me to try and do it on the server

lyric geyser
#

you can attempt

bold vault
#

alright

lyric geyser
#

but you called players.localplayer and shit

bold vault
#

i gotta brb for a while

lyric geyser
#

which is only local script working

lyric geyser
bold vault
#

yeah

lyric geyser
#

Also btw did you actually test if it worked? Because I don’t even think it would since you never did a playeradded or anything like that

bold vault
#

i did test, its weird because the scripts knows which player is first and which is second

#

but the number isnt changing

#

its almost working

#

its weird

#

because on player 2s client it knows that its the second player

#

but it prints 1 on both

#

ill recode it when i get back on the server or atleast try

#

i tihnk its an issue with players

lyric geyser
#

hm weird

#

so does that glitch it out

#

yea i just tested it

#

puts them in same position

lyric geyser
#
-- Services
local Players = game.Players:GetPlayers()

-- Tables
local CFramesTable = {
    CFrame.new(-3.344, 41.544, -32.03), -- 1st cframe
    CFrame.new(0, 0, 0), -- 2nd cframe and so on
}

-- Player Varibles
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
Character.PrimaryPart.Rotation = Vector3.new(0,180,0)

-- Funcs
local function SetPosition()
    for Number = 1, #Players do
        if Player == Players[Number] then
            HumanoidRootPart.CFrame = CFramesTable[Number]
        end
    end
end

SetPosition()

changed the code to this and it still works

#

changed it up a bit made it more workable, but still puts them in the same position

#

even though the loop is supposed to start at 1 then loop through the amount of players

#

its prob because it only loops once and sees only one person is there then stops looping

#

@bold vault got it to work

#

just put my thing above in a server sided script

#

ty for the help

#

i appreciate it alot

bold vault