PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Creation of a drawing canvas Code Sample 1

Creation of a drawing canvas Code Sample 1

Oct 01 2018, 3:08 AM PST

mouse.Button1Down:Connect(function()
	draw = true
	repeat
		local pos1=mouse.Hit.p --We will use mouse.Hit.p to get the current Mouse position. This returns a Vector3 value.
		wait()
		local pos2 = mouse.Hit.p -- What we're doing here is getting the second position after the wait(), which we will use later.
		local part = Instance.new("Part", workspace) -- Create the new part in the Workspace. <-- Instance.new("CLASS",PARENT)
		part.FormFactor = "Custom"
		part.CanCollide = false -- Make other parts be able to go trough it
		part.TopSurface = "SmoothNoOutlines" --Just some aesthetics.
		part.Anchored = true -- Make sure the part is anchored if you want it to maintain it's position, else it can move (and fall).
		part.BrickColor = BrickColor.new("Really black")
		part.Size=Vector3.new(0.5, 0.5, (pos1-pos2).magnitude )--We will use magnitude to get the distance between both points, and set the size (Z) to that distance.
		part.CFrame = CFrame.new( (pos1+pos2)/2, pos2 ) --This may seem a little complicated, but what we're doing is getting the part to be in between both pos1, & pos2.
	until not draw --Stop the loop when draw is no longer true.
end)