I’m working on some code that allows players to create some kind of ‘track’. There is one thing though I am unable to make with my skills, but I know that there are people on this forum who can probably do it in like 30 minutes.
Here’s what I want:
When I click, I want a part to appear at mouse.Hit. When I click again, I want a second part to appear, also at mouse.Hit. The two parts will now face each other:
Now comes the hard part I am unable to make. When I click to place the 3rd part at mouse.Hit, the first and second part do not change rotation, but instead a 4th part (part A) is made which is connected perfectly to the edge of the 2nd part and rotated in a way that it perfectly faces part 3.
Every step from now on will act the same as the last step. After clicking to place a new part, another part is created which is connected perfectly to the corner of the previous part so the two newly created parts face each other.
A few notes:
- All parts are placed at the exact same height, so for each part, only the rotation in the Y-axis shouldn’t equal 0.
- I have already made a small start with the code found below. It can only place the first and second part though. The variables PartWidth and PartLength (size in X-axis and Z-axis) in the code should still work when changed.
- The code below is a LocalScript found in the StarterGui.
Reward:
1.4k Robux after tax (= 3,5 dollars) (so make a shirt that costs 2k robux)
I think this is enough money for something I believe can be done in like 30 minutes. If you’re up for this, please respond to this topic with the code and a link to the T-shirt I have to buy.
My thanks in advance.
My attempt:
local mouse = script.Parent.Parent:GetMouse()
local PartWidth = 12
local PartLength = 2
local AtY = 10
local TimesClicked = 0
function CreatePart()
local P = Instance.new("Part")
P.FormFactor = "Custom"
P.BrickColor = BrickColor.new("Bright red")
P.Anchored = true
P.Size = Vector3.new(PartWidth, 1, PartLength)
return P
end
local AllParts = {}
mouse.Button1Down:connect(
function()
if mouse.Target then
TimesClicked = TimesClicked+1
local B = CreatePart()
if TimesClicked == 1 then
AllParts[#AllParts+1] = B
B.CFrame = CFrame.new(mouse.Hit.X, AtY, mouse.Hit.Z)
B.Parent = game.Workspace
elseif TimesClicked == 2 then
AllParts[#AllParts+1] = B
B.CFrame = CFrame.new(mouse.Hit.X, AtY, mouse.Hit.Z)
B.Parent = game.Workspace
AllParts[1].CFrame = CFrame.new(AllParts[1].Position, AllParts[2].Position)
AllParts[2].CFrame = CFrame.new(AllParts[2].Position, AllParts[1].Position)
elseif TimesClicked >= 3 then
-- the thing I can't do
end
end
end
)