So lets say the game has 10 parts and they all have a value owner, but I have 8 players how would I make that 8 random parts get a diffrent owner? btw the owner value is going to be the players name
local players = {...}
local parts = {...}
for _, player in #players do
local randomPart = table.remove(parts, math.random(#parts))
randomPart.Owner.Value = player.Name
end
where:
-
parts
is an array with all the parts, having aStringValue
under it namedOwner
. -
players
is an array with allPlayer
instances. -
#parts
>=#players
[quote=“Jqck, post:2, topic:2451673, username:Mystxry12”]
local players = {...}
local parts = {...}
what do i need to put in parts{} and palyers{} ??
I already mentioned it, please refer the post.
so I could do parts = {folder:getchildren()}
and then for the player
local players = game.Players:Getchildren()
Yes, please avoid asking yes/no questions
ok sorry, but at the #players part theres an error
ServerScriptService.QuestScripts.OwnersBackpacks:4: attempt to iterate over a number value
for _, player in players do
local randomPart = table.remove(parts, math.random(#parts))
randomPart.Owner.Value = player.Name
end
local players = game.Players:GetChildren()
local parts = game:WaitForChild("Workspace").HouseMap.Backpacks.BackpackParts:GetChildren()
for _, player in players do
local randomPart = table.remove(parts, math.random(#parts))
randomPart.Owner.Value = player.Name
end
none of the values are changing the loop isnt running I did printing it printed nothing.
Where is the script located? ServerScriptService
isn’t it supposed to be
for _, player in pairs(players) do
or am I thinking of something else
edit: I see, hasn’t been able to use studios in a while lol
Generalized iteration has already rolled out.
yes its located in serverscriptservice
what does that mean___________
Maybe it is running before any player joins, for the time being add this line at the top.
Players.PlayerAdded:Wait()
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.