#Im guessing im doing this COMPLETELY wrong, but how would i do this correctly
161 messages · Page 1 of 1 (latest)
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
like set the first players position to the first position
and second player to the second position?
yes
and so on
is this client or server
server sided
ight
also the first for loop in that script is completely useless lol just was testing smth
idk to be honest
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
ill just put it in a function
ok
so you can use it whenever
yeah dont worry i got you
👍
btw how do you detect the second the game starts?
do you just detect when a aplayer is added or something
the game starts the second the first player is added
ok
any code on the server that isnt in functions or waits will run instantly
because the server loads before the client
well if you keep it out of a function then it would just run instantly
before the player joins
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
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
so what if you just put a wait for a few seconds before the script is ran
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
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
ima see if there isnt a event that detects when the game is started
cuz there is one when it closes
alright
@bold vault if there isnt, I actually do have like a 10 second cutscene at the beginning for everyone every time they join
** You are now Level 4! **
Ok that’s true lmao
Why couldn’t we just detect when a player is added
Would that mess up the loop
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
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
Oh alr
i thought you only wanted it for the first person
we would want that to be client based then
Ohh ok , yea I want everyone
No no, like let’s say I want 8 people to be in the menu area
So then I create 8 different positions
I want everyone to see everyone there
OH
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 ?
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
Yea
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
So to do this it would have to be on a local script ?
you can do it on the server but it would be extremely complicated
thats why i say we do it on the client
i think lol
Lol
wait can you maybe explain what you think I want to happen
Idek if we’re on the same track right now
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
Yes
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
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
that works?
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
playeradded doesnt work on client i dont think
want me to try and do it on the server
you can attempt
alright
but you called players.localplayer and shit
i gotta brb for a while
which is only local script working
alright
yeah
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
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
hm weird
so does that glitch it out
yea i just tested it
puts them in same position
-- 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
alright no problem man good luck with your game