Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Vector3 not working with a part position?

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.

2 comments

0

To wait until the character has been added without having a Player.CharacterAdded:Connnect(function() end) you can just use Player.CharacterAdded:Wait() :) it works really well!

0

Just if you want it.

3 answers

✓ Accepted answer
  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)
  1. You're using a deprecated of Instance.new(), please don't
  1. You can just do Part.Position = character:WaitForChild("Head").Position

2 comments

0

You should explain what about Instance.new() is deprecated. Don't just say that it's deprecated.

0

Well, you're correct. I probably should have explained how parenting it using Instance.new sometimes causes the propertes to delay when being changed by a script

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)

1 comment

0

How is that correct code? You used a deprecated method of Instance.new

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.

5 comments

0

-1. Don't use deprecated items. Instance.new(instance, parent) is deprecated.

0

Then why did you use it?

0

@suspectshot108 Your code was deprecated as well you can't down vote mine, if you did the same

0

I did not do the same.

0

You did Instance.new(instance, parent) you should not set the parent from the instance.

This discussion is preserved as it was. New answers, comments, and votes are closed.