You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to make new part to the players position like a rain.
-
What is the issue? Include screenshots / videos if possible!
Issue is
19:38:53.404 Position is not a valid member of Player "Players.do0gdemon" - Server - Script:14
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I am dont excactly know what to do other that what I did!
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
game.Players.PlayerAdded:Connect(function(player)
for i = 20, 0, -1 do
local NewPart = Instance.new("Part")
NewPart.Parent = workspace
NewPart.Name = "NewPart"
NewPart.BrickColor = BrickColor.new("Baby blue")
NewPart.Material = "Neon"
NewPart.Position = Vector3.new(player.Position)
wait(1)
print(i)
end
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
The issue is that you’re trying to index an property called ‘Position’ of a Player, although that property is non-existent.
What you’re looking for is the Position property of BaseParts / CFrames.
And so, the Position property receives a Vector3, and returns the same; meaning you don’t need to use Vector3.new(Position) to convert it into itself.
Although, since Players don’t have a Position, their characters do. Players have the Character property, which returns their character. (Read the Developer Hub page for further information, there’s quite a lot to explain which is already listed there.)
Finally, your code should look like this:
game:GetService('Players').PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
for i = 0, 20 do
local NewPart = Instance.new("Part")
NewPart.Parent = workspace
NewPart.Name = "NewPart"
NewPart.BrickColor = BrickColor.new("Baby blue")
NewPart.Material = Enum.Material.Neon -- It's recommend to assign values which receive enums, using the full enum. (Instead of EnumName or EnumValue.)
NewPart.Position = Character.HumanoidRootPart.Position -- The HumanoidRootPart is often used when dealing with the position of the player. If I'm not mistaken, it's the PrimaryPart of the character, therefore why it's used to do so.
wait(1)
print(i)
end
end)
end)
Quick note: The code shown will create the parts each time the player respawns - meaning if you want to do this only once, just listen to the event once using Player.CharacterAdded:Wait(), instead of connecting the event to an function. (Which will listen to the event each time it is fired, although :Wait will yield the thread until the event is fired, although once the event is fired, it will stop yielding. And yes, I badly explained this.)
2 Likes
To get the player position, you should get the position of the player’s torso with player.Character.HumanoidRootPart.Position. However, a PlayerAdded event can often fire before the player’s character and torso are added so you will need to wait for those to load.
game.Players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait() -- wait for character to load (if needed)
local torso = character:WaitForChild("HumanoidRootPart") -- wait for torso to load
print(torso.Position) -- get player's position
end)
2 Likes
This is actually really cool, I will use this in my other projects thanks
(will mark you as solution=)