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

How to add to a position when using instance.new?

I'm trying to make a function which when a player joins it creates a new part in a different position, I want them to separate by adding to the position. Here is the code I used:

`game.Players.PlayerAdded:Connect(function(newbuildingspot)

local NewBuildingSpot = Instance.new("Part")
NewBuildingSpot.Parent = game.BuildingSpotFolder
NewBuildingSpot.Size(3,5,50)
NewBuildingSpot.BrickColor = BrickColor.new("Beige")
NewBuildingSpot.Position(+0,+12,+15) `

end) Mainly concerned on the last one and wanted I hope that someone with more experience can point out my error/s.

3 comments

0

i think you should do NewBuildingSpot.Position = whateverthingitis.Position + Vector3.new(0,12,15)

0

Also i'm not sure wether you should be using .Position or .CFrame. Because last time i tried using .Position it kinda resulted in an undefined behavior lol

0

Thank you for your reply, didn't seem to work for me when I used both .Position and .CFrame., I did end up finding the solution on the DevForums after trying .Position.

1 answer

You should use a Local Script, which only affect on player's client (only himself, like the Minecraft ender chest)

game.Players.PlayerAdded:Connect(function(player)
	local NewBuildingSpot = Instance.new("Part", player.CurrentCamera)
	NewBuildingSpot.Parent = game.BuildingSpotFolder
	NewBuildingSpot.Size(3,5,50)
	NewBuildingSpot.BrickColor = BrickColor.new("Beige")
	NewBuildingSpot.Position(math.Random(0,12), math.Random(0,15)) -- Randomize the Building Spot's Position
end)

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