Im trying to sit npc's from a folder into a random seat. When I attempt to use Seat:Sit(), it returns an error. I tried to add wait() and a repeat wait() until to determine if the humanoid actually exists, and if the npc exists and is in a folder in the workspace. Still doesn't work. Help?
Main code:
local getRandomModule = require(script.Random) -- will include in next script
function updateChairs()
local players = game.Players:GetChildren()
local npcs = game.ReplicatedStorage.NPCs:GetChildren()
local chairs = workspace.TableSet.Chairs:GetChildren()
local difference = #npcs - #players
for i = 1,difference,1 do
local npc = npcs[i]:Clone()
npc.Parent = workspace.Holders
local hum = npc:WaitForChild("Humanoid")
repeat wait() until hum.Parent == npc and npc.Parent == workspace.Holders -- waiting until hum is parented/exists and if npc exists in workspace.Holders but no effect
local chair = getRandomModule.getRandom(chairs,"Occupant",nil)
wait(1) -- added a wait() but still no effects
chair.Seat:Sit(hum)
hum.Sit = true
end
end
game.Players.PlayerAdded:Connect(function()
updateChairs()
end)
I will include the module script as well just in case that is the problem, though it seems to work perfectly fine
local module = {}
function module.getRandom(table,value,desired)
local random = table[math.random(1,#table)]
if value and desired then
if random[value] == desired then
return random
else
repeat
random = table[math.random(1,#table)]
wait()
until random[value] == desired
return random
end
else
return random
end
end
return module
Thanks :)
