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

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

Asked by 3 years ago
Edited 3 years ago

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.

0
i think you should do NewBuildingSpot.Position = whateverthingitis.Position + Vector3.new(0,12,15) iMazariuz 36 — 3y
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 iMazariuz 36 — 3y
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. nafey200 59 — 3y

1 answer

Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

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)
Ad

Answer this question