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

Making Games Like StickMasterLuke's "Draw It"?

Asked by
vebel 2
7 years ago

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

Log in to vote
1
Answered by
mattscy 3725 Moderation Voter Community Moderator
7 years ago

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

Answer this question