Whiteboard colour issue

I’m making a windows xp game and the changing colour of the dot isn’t working when I add the new line of code it works but it don’t work with colour it all I have made a previous post before days back but I didn’t get a strong answer.

Code:

local frame = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()
local ClearButton = script.Parent.ClearButton

local x
local y

local pressed = false

mouse.Button1Down:Connect(function()
pressed = true
end)

mouse.Button1Up:Connect(function()
pressed = false
end)

game:GetService(“RunService”).RenderStepped:Connect(function()
x = mouse.X
y = mouse.Y
if pressed == true then
local dot = Instance.new(“Frame”)
dot.Name = “Dot”
dot.Parent = frame
dot.BackgroundColor3 = Color3.new(0,0,0)
dot.Size = UDim2.new(0, 6, 0, 6)
dot.Position = UDim2.new(0, x - frame.AbsolutePosition.X, 0, y - frame.AbsolutePosition.Y)
end
end)

ClearButton.MouseButton1Click:Connect(function()
for i, q in pairs(frame:GetChildren()) do
if q.Name == “Dot” then
q:Destroy()
end
end
end)
color = Color3.fromRGB(0, 0, 0)
dot.BackgroundColor3 = color
RedButton.MouseButton1Click:Connect(function()
color = Color3.fromRGB(0, 0, 0)
local color = Color3.fromRGB(255, 0, 0)
end)

I have reviewed the code over and over again and nothing

Output Says:

Players.3DRobloxGameDev.PlayerGui.Options.Startup.frame.LocalScript:39: attempt to index nil with ‘BackgroundColor3’

2 Likes

Yes, because you create a dot for a function, not for script, so you can only edit in function where you create it.

EXAMPLE:

for function:

function Test()
local dot = "Yes"
print(dot) --> "Yes"
end

print(dot) --> nil

for script:

local dot

function Test()
dot = "Yes"
print(dot) --> "Yes"
end

print(dot) --> "Yes"

So you must add on top local dot and in function change local dot to dot.

Is it like this or is it not this

color = Color3.fromRGB(0, 0, 0)
local.dot = color
RedButton.MouseButton1Click:Connect(function()
color = Color3.fromRGB(0, 0, 0)
local color = Color3.fromRGB(255, 0, 0)
end)

like this:

local frame = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()
local ClearButton = script.Parent.ClearButton
local dot -- <-- here

local x
local y

local pressed = false

mouse.Button1Down:Connect(function()
pressed = true
end)

mouse.Button1Up:Connect(function()
pressed = false
end)

game:GetService("RunService").RenderStepped:Connect(function()
x = mouse.X
y = mouse.Y
if pressed == true then
dot = Instance.new("Frame") -- <--here
dot.Name = "Dot"
dot.Parent = frame
dot.BackgroundColor3 = Color3.new(0,0,0)
dot.Size = UDim2.new(0, 6, 0, 6)
dot.Position = UDim2.new(0, x - frame.AbsolutePosition.X, 0, y - frame.AbsolutePosition.Y)
end
end)

ClearButton.MouseButton1Click:Connect(function()
for i, q in pairs(frame:GetChildren()) do
if q.Name == "Dot" then
q:Destroy()
end
end
end)
RedButton.MouseButton1Click:Connect(function()
	dot.BackgroundColor3 = Color3.fromRGB(255, 0, 0)  -- <here
end)
1 Like

I have high hopes for this script but the output doesent seem so…
I have had to channge the ”” to “” because it was red underlined

Output:

Unable to create an Instance of type “frame”

Yes you must all replace. “frame” → "Frame". The web does it if you don’t put it in the right format.

1 Like

That is so weird its acting like nothing is wrong with it in the output but don’t change colour i also appreciate you for helping me as I am a weak coder!

We have some progress I made some colour on adding more references but it dont colour it how i wanted it only colours it like 1 part that was recently done not an entire thing for colour

You will do the same as in the function where you delete dot just instead of deleting you will paint.

RedButton.MouseButton1Click:Connect(function()
	for i, q in pairs(frame:GetChildren()) do
		if q.Name == "Dot" then
			q.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
		end
	end
end)
1 Like

This did work actually cheers but you pain it and click red and then it changes it red how would you make it like press red then draw and it draws red

You will add new value on top local dotColor = Color3.fromRGB(0,0,0) its default color.
In function with runservice make dot.BackgroundColor3 = dotColor and in last function under q.BackgroundColor3 =… add dotColor = q.BackgroundColor3

Like that or something else?

Last function is not correct.Its only dotColor = q.backgroundcolor3

Yes, now is all correct. Try it what it make.

Its kind of the same… it basically when I do a red colour and then change to a blue colour it changes it all to blue

And how would you like it? (random text)

Well so basically if I don’t describe myself right ill have a picture up so when you go click for instance red it changes the part to red then you click blue and it keeps the other red but makes the new blue.

So you want it as in painting? I click on red I paint red, I click on blue I paint blue?

1 Like

Yeah i want it like that if possible