But now I have a problem… Dots are not drawn where you click (since they are being drawn server side):
Client:
local lPlr = game.Players.LocalPlayer
local mouse = lPlr:GetMouse()
local uis = game:GetService("UserInputService")
local Flash_DrawScript = game:GetService("ReplicatedStorage"):WaitForChild("Flash_DrawScript")
local isMouseButtonDown = false
local function InputBegan(input)
local inputType = input.UserInputType
if inputType == Enum.UserInputType.MouseButton1 then
isMouseButtonDown = true
end
end
function InputEnded(input)
local inputType = input.UserInputType
if inputType == Enum.UserInputType.MouseButton1 then
isMouseButtonDown = false
end
end
local function Paint(X, Y)
if isMouseButtonDown == false then return end
return Flash_DrawScript:FireServer(X, Y)
end
uis.InputBegan:Connect(InputBegan)
uis.InputEnded:Connect(InputEnded)
for _, frame in ipairs(lPlr.PlayerGui.DrawGui:GetChildren()) do
if not frame:IsA("Frame") or frame.Name == "Options" then return end
print(frame)
frame.MouseMoved:Connect(Paint)
end
Server:
Flash_DrawScript.OnServerEvent:Connect(function(plr, X, Y)
print("X: "..X.." Y: "..Y)
for _, frame in ipairs(plr.PlayerGui.DrawGui:GetChildren()) do
if not frame:IsA("Frame") or frame.Name == "Options" then return end
local gui_X = frame.AbsolutePosition.X
local gui_Y = frame.AbsolutePosition.Y
local offset = Vector2.new(math.abs(X - gui_X), math.abs(Y - gui_Y - 36))
local dot = Instance.new("ImageLabel")
dot.Parent = frame
dot.Position = UDim2.new(0, offset.X, 0, offset.Y)
dot.Name = "Dot"
dot.ImageColor3 = Color3.fromRGB(0, 0, 0)
dot.BackgroundTransparency = 1
dot.Size = UDim2.new(0, 4, 0, 4)
dot.Image = "http://www.roblox.com/asset/?id=279918838"
return dot
end
end)
Btw, I know some things are a little disorganized or poorly optimized, but first I’m focusing on making this work.
I don’t recommend doing this on the server. VFX and local things should strictly be done on the client.
However, your script is likely not working because of this:
After the first iteration of a frame, the loop will just end there. In addition to the fact that you cannot return a value through RemoteEvents (RemoteFunctions serve that purpose)
local lPlr = game.Players.LocalPlayer
local mouse = lPlr:GetMouse()
local uis = game:GetService("UserInputService")
local Flash_DrawScript = game:GetService("ReplicatedStorage"):WaitForChild("Flash_DrawScript")
local isMouseButtonDown = false
local function InputBegan(input)
local inputType = input.UserInputType
if inputType == Enum.UserInputType.MouseButton1 then
isMouseButtonDown = true
end
end
function InputEnded(input)
local inputType = input.UserInputType
if inputType == Enum.UserInputType.MouseButton1 then
isMouseButtonDown = false
end
end
for _, frame in ipairs(lPlr.PlayerGui.DrawGui:GetChildren()) do
if not frame:IsA("Frame") or frame.Name == "Options" then return end
local function Paint(X, Y)
if isMouseButtonDown == false then return end
Flash_DrawScript:FireServer(frame, X, Y, isMouseButtonDown)
end
uis.InputBegan:Connect(InputBegan)
uis.InputEnded:Connect(InputEnded)
frame.MouseMoved:Connect(Paint)
end