game.Players.PlayerAdded:Connect(function(Player) wait(2) local Part = Instance.new("Part",workspace) Part.Position = Vector3.new(Player.Character.Head.Position) end)
Does not work, it does not give any errors, it spawns at a random place in the workspace.
1) You're not checking if the player has a character or anything, so this could error if a player doesn't have a character. Simply add a CharacterAdded
event to the player and do the scripting in the CharacterAdded function.
Example:
game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) --code end) end)
2) You're using a deprecated of Instance.new(), please don't
Part.Position = character:WaitForChild("Head").Position
I'm going to answer with some more correct code so here you go:
First of all, you are using Instance, parent which is deprecated. It doesn't effect your code but you shouldn't use it. Next, you can just use CFrame to get the job done. It's easy to remember, to use, and it's a fast way to change positions.
game.Players.PlayerAdded:Connect(function(Player) wait(2) local Part = Instance.new("Part") Part.CFrame = CFrame.new(Player.Character.Head.Position) part.Parent = workspace end)
You'll have to use CFrame to set the position to the head's position and do not forget to anchor the part, there has to be a delay not less than 2 Seconds so you can actually see the effect and also so it can gather the player's head's Position as it was implemented in the following; Code:
game.Players.PlayerAdded:Connect(function(plr) --Getting Joined Player plr.CharacterAdded:Connect(function(char) --Getting the player's character when it's not nil wait(2) local part = Instance.new("Part", workspace) --Making a new brick part.Anchored = true part.CFrame = CFrame.new(char.Head.Position) --Setting the brick's position to head's position end) end)
Hope this helped.