Help with a script!

I need help with this script says a error on the client 14:15:04.302 Players.ELHOMBRETAQUITO.PlayerGui.ClickButtons.Manager:31: attempt to index nil with ‘BackgroundColor3’ - Cliente - Manager:31
Here’s my code, pls respond fast!

local RS = game:GetService("ReplicatedStorage")
local Remotes = RS.Remotes

local Gui = script.Parent
local Frame = Gui.Frame

local Click = Frame.Click
local FastAuto = Frame.Rapido
local RegularAuto = Frame.Regular

local STROKE_OFF_COLOR = Color3.fromRGB(158, 61, 61)
local STROKE_ON_COLOR = Color3.fromRGB(15, 156, 62)
local  IMAGE_BACKGROUND_COLOR_OFF = Color3.fromRGB(255, 107, 107)
local  IMAGE_BACKGROUND_COLOR_ON = Color3.fromRGB(25, 255, 102)
local CLICK_TEXT_TEMPLATE = "Auto Clicker TYPE (MODE)"

local RegularMode = false
local FastMode = false

local function UpdateButton(buttonType: "Regular" | "Rapido", mode: boolean)
	local button
	if buttonType == "Regular" then
		button = RegularAuto
		RegularMode = mode
	else
		buttonType = FastAuto
		FastMode = mode
	end
	
	if mode then
		button.BackgroundColor3 =  IMAGE_BACKGROUND_COLOR_ON 
		button.Label.Text = CLICK_TEXT_TEMPLATE:gsub("TYPE", buttonType):gsub("MODE", "Activado")
		button.Label.TextColor3 =  IMAGE_BACKGROUND_COLOR_ON
		button.UIStroke.Color = STROKE_ON_COLOR
	else
		button.BackgroundColor3  =  IMAGE_BACKGROUND_COLOR_OFF 
		button.Label.Text = CLICK_TEXT_TEMPLATE:gsub("TYPE", buttonType):gsub("MODE", "Desactivado")
		button.Label.TextColor3 =  IMAGE_BACKGROUND_COLOR_OFF
		button.UIStroke.Color = STROKE_OFF_COLOR
	end
end

FastAuto.MouseButton1Click:Connect(function()
	Remotes.UpdateAutoClicker:FireServer("Rapido")
end)
RegularAuto.MouseButton1Click:Connect(function()
	Remotes.UpdateAutoClicker:FireServer("Regular")
end)

Click.MouseButton1Click:Connect(function()
	Remotes.Click:FireServer()
end)

Remotes.UpdateAutoClicker.OnClientEvent:Connect(UpdateButton)
UpdateButton("Regular", Remotes.GetAutoClickMode:InvokeServer("Regular"))
UpdateButton("Rapido", Remotes.GetAutoClickMode:InvokeServer("Rapido"))
2 Likes

if the buttonType isnt Regular then the button variable inside the UpdateButton function is gonna be nil so youre trying to set the background color of nothing here:

And how i type it dude?
Like add a nil?

I updated the script, but i have an error see, if u can solve it…

local RS = game:GetService("ReplicatedStorage")
local Remotes = RS.Remotes

local Gui = script.Parent
local Frame = Gui.Frame

local Click = Frame.Click
local FastAuto = Frame.Rapido
local RegularAuto = Frame.Regular

local STROKE_OFF_COLOR = Color3.fromRGB(158, 61, 61)
local STROKE_ON_COLOR = Color3.fromRGB(15, 156, 62)
local  IMAGE_BACKGROUND_COLOR_OFF = Color3.fromRGB(255, 107, 107)
local  IMAGE_BACKGROUND_COLOR_ON = Color3.fromRGB(25, 255, 102)
local CLICK_TEXT_TEMPLATE = "Auto Clicker TYPE (MODE)"

local RegularMode = false
local FastMode = false

local function UpdateButton(buttonType: "Regular" | "Rapido", mode: boolean)
	local button
	if buttonType == "Regular" then
		button = RegularAuto
		RegularMode = mode
	elseif buttonType == "FastAuto" then
		buttonType = FastAuto
		FastMode = mode
	end
	
	if mode then
		button.BackgroundColor3 =  IMAGE_BACKGROUND_COLOR_ON
	    button.Label.Text = CLICK_TEXT_TEMPLATE:gsub("TYPE", buttonType):gsub("MODE", "Activado")
		button.Label.TextColor3 =  IMAGE_BACKGROUND_COLOR_ON
		button.UIStroke.Color = STROKE_ON_COLOR
	elseif 
		button.BackgroundColor3  ==  IMAGE_BACKGROUND_COLOR_OFF 
		then button.Label.Text = CLICK_TEXT_TEMPLATE:gsub("TYPE", buttonType):gsub("MODE", "Desactivado")
		button.Label.TextColor3 = IMAGE_BACKGROUND_COLOR_OFF
		button.UIStroke.Color = STROKE_OFF_COLOR
	end
end

FastAuto.MouseButton1Click:Connect(function()
	Remotes.UpdateAutoClicker:FireServer("Rapido")
end)
RegularAuto.MouseButton1Click:Connect(function()
	Remotes.UpdateAutoClicker:FireServer("Regular")
end)

Click.MouseButton1Click:Connect(function()
	Remotes.Click:FireServer()
end)

Remotes.UpdateAutoClicker.OnClientEvent:Connect(UpdateButton)
UpdateButton("Regular", Remotes.GetAutoClickMode:InvokeServer("Regular"))
UpdateButton("Rapido", Remotes.GetAutoClickMode:InvokeServer("Rapido"))

The error is: 14:37:04.200 Players.ELHOMBRETAQUITO.PlayerGui.ClickButtons.Manager:31: attempt to index nil with ‘BackgroundColor3’ - Cliente - Manager:31

Where did you put the script in?

In StarterGui.ClickButtons.Manager

The issue is that you don’t set button to anything for the second if statement when it is equal to “FastAuto”, leaving it as undefined (nil) which is where the error comes from.
(Change buttonType to button)

Lo que me salio fue: 14:55:39.047 Players.ELHOMBRETAQUITO.PlayerGui.ClickButtons.Manager:39: attempt to index nil with ‘BackgroundColor3’ - Cliente - Manager:39
Y cambie el script a:

local RS = game:GetService("ReplicatedStorage")
local Remotes = RS.Remotes

local Gui = script.Parent
local Frame = Gui.Frame

local Click = Frame.Click
local FastAuto = Frame.Rapido
local RegularAuto = Frame.Regular

local STROKE_OFF_COLOR = Color3.fromRGB(158, 61, 61)
local STROKE_ON_COLOR = Color3.fromRGB(15, 156, 62)
local  IMAGE_BACKGROUND_COLOR_OFF = Color3.fromRGB(255, 107, 107)
local  IMAGE_BACKGROUND_COLOR_ON = Color3.fromRGB(25, 255, 102)
local CLICK_TEXT_TEMPLATE = "Auto Clicker TYPE (MODE)"

local RegularMode = false
local FastMode = false

local function UpdateButton(buttonType: "Regular" | "Rapido", mode: GuiObject)
	local button
	if buttonType == "Regular" then
		buttonType = RegularAuto
		RegularMode = mode
		end
		if button == "FastAuto" then
			button = FastAuto
			FastMode = mode
		end
	
	
	
	if mode then
		button.BackgroundColor3 =  IMAGE_BACKGROUND_COLOR_ON
	    button.Label.Text = CLICK_TEXT_TEMPLATE:gsub("TYPE", buttonType):gsub("MODE", "Activado")
		button.Label.TextColor3 =  IMAGE_BACKGROUND_COLOR_ON
		button.UIStroke.Color = STROKE_ON_COLOR
	elseif
		 button.BackgroundColor3  ==  IMAGE_BACKGROUND_COLOR_OFF 
		 then button.Label.Text = CLICK_TEXT_TEMPLATE:gsub("TYPE", buttonType):gsub("MODE", "Desactivado")
		button.Label.TextColor3 = IMAGE_BACKGROUND_COLOR_OFF
		button.UIStroke.Color = STROKE_OFF_COLOR
	end
end

FastAuto.MouseButton1Click:Connect(function()
	Remotes.UpdateAutoClicker:FireServer("Rapido")
end)
RegularAuto.MouseButton1Click:Connect(function()
	Remotes.UpdateAutoClicker:FireServer("Regular")
end)

Click.MouseButton1Click:Connect(function()
	Remotes.Click:FireServer()
end)

Remotes.UpdateAutoClicker.OnClientEvent:Connect(UpdateButton)
UpdateButton("Regular", Remotes.GetAutoClickMode:InvokeServer("Regular"))
UpdateButton("Rapido", Remotes.GetAutoClickMode:InvokeServer("Rapido"))

Now i have only one error this: 15:00:05.796 Players.ELHOMBRETAQUITO.PlayerGui.ClickButtons.Manager:34: attempt to index nil with ‘BackgroundColor3’ - Cliente - Manager:34

script again:

local RS = game:GetService("ReplicatedStorage")
local Remotes = RS.Remotes

local Gui = script.Parent
local Frame = Gui.Frame

local Click = Frame.Click
local FastAuto = Frame.Rapido
local RegularAuto = Frame.Regular

local STROKE_OFF_COLOR = Color3.fromRGB(158, 61, 61)
local STROKE_ON_COLOR = Color3.fromRGB(15, 156, 62)
local  IMAGE_BACKGROUND_COLOR_OFF = Color3.fromRGB(255, 107, 107)
local  IMAGE_BACKGROUND_COLOR_ON = Color3.fromRGB(25, 255, 102)
local CLICK_TEXT_TEMPLATE = "Auto Clicker TYPE (MODE)"

local RegularMode = false
local FastMode = false

local function UpdateButton(buttonType: "Regular" | "Rapido", mode: GuiObject)
	local button
	if buttonType == "Regular" then
		buttonType = RegularAuto
		RegularMode = mode
		end
		if  button == "FastAuto" then
			button = FastAuto
			FastMode = mode
		end
		if mode then
		button.BackgroundColor3 =  IMAGE_BACKGROUND_COLOR_ON
	    button.Label.Text = CLICK_TEXT_TEMPLATE:gsub("TYPE", buttonType):gsub("MODE", "Activado")
		button.Label.TextColor3 =  IMAGE_BACKGROUND_COLOR_ON
		button.UIStroke.Color = STROKE_ON_COLOR
		end
		if mode then
			button.BackgroundColor3  =  IMAGE_BACKGROUND_COLOR_OFF 
			button.Label.Text = CLICK_TEXT_TEMPLATE:gsub("TYPE", buttonType):gsub("MODE", "Desactivado")
	button.Label.TextColor3 = IMAGE_BACKGROUND_COLOR_OFF
	button.UIStroke.Color = STROKE_OFF_COLOR
		end
end

FastAuto.MouseButton1Click:Connect(function()
	Remotes.UpdateAutoClicker:FireServer("Rapido")
end)
RegularAuto.MouseButton1Click:Connect(function()
	Remotes.UpdateAutoClicker:FireServer("Regular")
end)

Click.MouseButton1Click:Connect(function()
	Remotes.Click:FireServer()
end)

Remotes.UpdateAutoClicker.OnClientEvent:Connect(UpdateButton)
UpdateButton("Regular", Remotes.GetAutoClickMode:InvokeServer("Regular"))
UpdateButton("Rapido", Remotes.GetAutoClickMode:InvokeServer("Rapido"))

Pense que lo solucione, pero no…
Ahora cuando doy click tanto al boton normal de click como al de autoclick, no funciona :frowning:

Ahora solo funciona con el click que sad

You’re defining button as null first then the next statement is try to check if button is “FastAuto” which will evaluate to false. Did you mean “if buttonType” == “FastAuto” ?

local button
if buttonType == “Regular” then
buttonType = RegularAuto
RegularMode = mode
end
if button == “FastAuto” then
button = FastAuto
FastMode = mode
end

Btw, if buttonType is Regular you’re not re-defining button either. Should buttonType = RegularAuto actually be button = RegularAuto?

In essence this is the updated code:

local button
if buttonType == "Regular" then
	button = RegularAuto
	RegularMode = mode
end
if  buttonType == "FastAuto" then
	button = FastAuto
	FastMode = mode
end

Oficialmente eres la solucion!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.