Hello, I am trying to make a 32x32 pixel art system but have no idea what to do. I tried to use viewportframes with parts but I had no idea how to detect part clicks and also don’t want to have 1024 buttons in the gui. How should I do this?
Hi! If you just need to detect clicks, use this:
local plr = game.Players.LocalPlayer
local frame = script.Parent
local moved
for i,v in pairs(frame:GetChildren()) do
if v:IsA("ViewportFrame") then
v.MouseEnter:Connect(function()
moved = v
end)
v.MouseLeave:Connect(function()
moved = nil
end)
end
end
plr:GetMouse().Button1Down:Connect(function()
if moved ~= nil then
--interact function
end
end)
I will try this tomorrow as I am about to go to sleep. thanks!
Oh I need to be able to change the color of the part inside the viewportframe. How can I do this?
I just found out you cant interact with the parts inside the viewportframes.
I keep searching and I can’t find anything I really need help.
Try this script:
local plr = game.Players.LocalPlayer
local frame = script.Parent
local moved
local last
for i,v in pairs(frame:GetChildren()) do
if v:IsA("ViewportFrame") then
v.MouseEnter:Connect(function()
moved = v
end)
v.MouseLeave:Connect(function()
moved = nil
end)
end
end
plr:GetMouse().Button1Down:Connect(function()
if moved ~= nil then
if moved ~= last then
--if you need to get a part
moved:FindFirstChild("PART").Color = Color3.new(math.random(),math.random(),math.random())
--if you need to get a model
local model = moved:FindFirstChild("MODEL")
local partInside = model:FindFirstChild("PART")
partInside.Color = Color3.new(math.random(),math.random(),math.random())
end
end
last = moved
end)
I think that would only change the color of one single part called “PART”
yeah. If you need something more, just write
I have a 32x32 grid of pixels and want a painting system. What you showed me wont work.
Did you place this script into the frame that is board?
I am so confused where am I supposed to the script and where is the viewportframe and where are the parts in it?
Frame that have viewportframes
I have 1 viewportframe with 1024 parts inside of it.
uhhhh, wha? How does this work? Can you show me explorer?
I have a viewportframe with a ton of parts. the parts are the pixels. I am trying to make it so you can change the color of the parts by dragging over them.
can you show me ur screen? sdfhdtherhehj
I have a script to duplicate a part and position it.