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

Making Games Like StickMasterLuke's "Draw It"?

I just wanted to try and attempt recreating his game from scratch. (I wanted to do it in SurfaceGui, instead of ScreenGui) But I ran into a problem.

So currently, I use Localscript for this. Localscript is in StarterPack, chalkboard is the part name (in Workspace), inside chalkboard part, there is a SurfaceGui, and inside the SurfaceGui, there is a Frame.

chalkboard = workspace.chalkboard
frame = chalkboard.SurfaceGui.Frame
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

function draw()
	if mouse.Target == chalkboard then 
		while true do 
			wait()
			local mark = Instance.new("Frame", frame)
			mark.Size = UDim2.new(0,1,0,1)
			mark.Position = UDim2.new(0,mouse.X, 0, mouse.Y)
			mark.BackgroundColor3 = Color3.fromRGB(0,0,0)
		end
	end
	
end

mouse.Button1Down:connect(draw)

When I execute, it does draw, but how do you get it so that when player clicks on the SurfaceGui, it draws in that spot of the Frame, instead of Mouse position??? Thanks.

1 answer

You could try getting the difference between the mouse position and the frame, and then offsetting the mark by that difference.

local mousePos = Vector2.new(mouse.X,mouse.Y)
local offset = mousePos - frame.AbsolutePosition
mark.Position = UDim2.new(0,offset.X,0,offset.Y)

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