So I've been trying to get a part to spawn above a random player, and I've tried a bunch of different scripts with various errors, most recently getting a " randomPlayer is not a valid member of DataModel " error.
Here's my code, any advice would be greatly appreciated.
local randomPlayer = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())] while true do wait(1) part = script.Parent.Debris:clone() part.Parent = script.Parent part.Anchored = true part.Position = game.randomPlayer.Character.Torso.Position end
You didn't index the table the right way, plus you didn't get the character the right way. Below you can find a way to index the table correctly.
local PlayersTable = game.Players:GetPlayers() local RandomPlayer = PlayersTable[math.random(1,#PlayersTable)]
To fix your player issue, you have to first understand that the Players part of the workspace only holds the clients. To get their actual characters, you have to find them from workspace. To do that, get the name of the player(which is whatever RandomPlayer is), and do
game.workspace:FindFirstChild(RandomPlayer)
Then, I'd probably just use a weld to make the part follow the player.