Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Vector3 not working with a part position?

Asked by 5 years ago
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.

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! namespace25 594 — 5y
0
Just if you want it. namespace25 594 — 5y

3 answers

Log in to vote
1
Answered by
blockmask 374 Moderation Voter
5 years ago
Edited 5 years ago

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

  1. You can just do Part.Position = character:WaitForChild("Head").Position
0
You should explain what about Instance.new() is deprecated. Don't just say that it's deprecated. namespace25 594 — 5y
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 blockmask 374 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
0
How is that correct code? You used a deprecated method of Instance.new blockmask 374 — 5y
Log in to vote
-1
Answered by
Divistern 127
5 years ago

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.

0
-1. Don't use deprecated items. Instance.new(instance, parent) is deprecated. namespace25 594 — 5y
0
Then why did you use it? blockmask 374 — 5y
0
@suspectshot108 Your code was deprecated as well you can't down vote mine, if you did the same Divistern 127 — 5y
0
I did not do the same. namespace25 594 — 5y
0
You did Instance.new(instance, parent) you should not set the parent from the instance. namespace25 594 — 5y

Answer this question