Studio crashes when textbox text changes

making a rgb remote controller for my bus ceiling lights.just realised that players can put * # ! characters to the boxes.i fixed it too but now when i change the number in the box studio crashes till its restarted.

there is even no while loop or repeat that makes it.

Guys sorry about my spotify song i always forgot that and realize when i turn off the record.

cant believe that i forgot the script im dumb than my toilet
oh actually the studio crashed

1 Like

Debugging error handling, and data binding issues check it. Also more context is needed you might need to narrow further with this. Also check the documentation related to this context.

(Btw it’s Mr gates I know you lol)

i dont remember you when we met lol
for the script its here:

local Colors = {
	["kırmızı"] = Color3.fromRGB(255,0,0),
	["mavi"] = Color3.fromRGB(0,0,255),
	["yeşil"] = Color3.fromRGB(0,255,0),
	["pembe"] = Color3.fromRGB(255, 0, 255),
	["açık mavi"] = Color3.fromRGB(0,255,255),
	["sarı"] = Color3.fromRGB(255,255),
	["beyaz"] = Color3.fromRGB(255,255,255)
}

local ColourBox = script.Parent.ColourBox
local Description = script.Parent.Description
local RGBColourName = script.Parent.RGBColourName
local RedColourBox = script.Parent.RedColourBox
local GreenColourBox = script.Parent.GreenColourBox
local BlueColourBox = script.Parent.BlueColourBox
local RedColourPreview = script.Parent.RedColourPreview
local GreenColourPreview = script.Parent.GreenColourPreview
local BlueColourPreview = script.Parent.BlueColourPreview
local RGBColourPreview = script.Parent.RGBColourPreview
local Timer = 0

local function Creatimer()
	Timer = 200
	Description.Text = "İstediğiniz renginizi ismi/RGB renkleri/Hex renkleri ile değiştirebilirsiniz.Sonraki Değiştirme hakkı:200"
	repeat
		task.wait(1)
		Timer -= 1
		Description.Text = "İstediğiniz renginizi ismi/RGB renkleri/Hex renkleri ile değiştirebilirsiniz.Sonraki Değiştirme hakkı:"..Timer
	until Timer <= 0
	script.Parent.CanUse.Value = true
end

ColourBox:GetPropertyChangedSignal("Text"):Connect(function()
	script.Typewriter:Play()
	ColourBox.Text = string.gsub(ColourBox.Text,"%d","")
end)

RedColourBox:GetPropertyChangedSignal("Text"):Connect(function()
	script.Typewriter:Play()
	RedColourBox.Text = string.gsub(RedColourBox.Text,"%a","")
	RedColourBox.Text = string.gsub(RedColourBox.Text,"%p","")
	RedColourBox.Text = string.gsub(RedColourBox.Text,"","0")
	RedColourBox.Text = string.sub(RedColourBox.Text,1,3)
	RedColourPreview.BackgroundColor3 = Color3.fromRGB(tonumber(RedColourBox.Text),0,0)
	RGBColourPreview.BackgroundColor3 = Color3.new(RedColourPreview.BackgroundColor3.R,GreenColourPreview.BackgroundColor3.G,BlueColourPreview.BackgroundColor3.B)
end)

GreenColourBox:GetPropertyChangedSignal("Text"):Connect(function()
	script.Typewriter:Play()
	GreenColourBox.Text = string.gsub(GreenColourBox.Text,"%a","")
	GreenColourBox.Text = string.gsub(GreenColourBox.Text,"%p","")
	GreenColourBox.Text = string.gsub(GreenColourBox.Text,"","0")
	GreenColourBox.Text = string.sub(GreenColourBox.Text,1,3)
	GreenColourPreview.BackgroundColor3 = Color3.fromRGB(0,tonumber(GreenColourBox.Text),0)
	RGBColourPreview.BackgroundColor3 = Color3.new(RedColourPreview.BackgroundColor3.R,GreenColourPreview.BackgroundColor3.G,BlueColourPreview.BackgroundColor3.B)
end)

BlueColourBox:GetPropertyChangedSignal("Text"):Connect(function()
	script.Typewriter:Play()
	BlueColourBox.Text = string.gsub(BlueColourBox.Text,"%a","")
	BlueColourBox.Text = string.gsub(BlueColourBox.Text,"%p","")
	BlueColourBox.Text = string.gsub(BlueColourBox.Text,"","0")
	BlueColourBox.Text = string.sub(BlueColourBox.Text,1,3)
	BlueColourPreview.BackgroundColor3 = Color3.fromRGB(0,0,tonumber(BlueColourBox.Text))
	RGBColourPreview.BackgroundColor3 = Color3.new(RedColourPreview.BackgroundColor3.R,GreenColourPreview.BackgroundColor3.G,BlueColourPreview.BackgroundColor3.B)
end)

RGBColourPreview.Activated:Connect(function()
	local Matches = false
	local Colourname = nil
	for i,v in pairs(Colors) do
		if RGBColourPreview.BackgroundColor3 == v then
			Colourname = i
			Matches = true
		end
	end
	if Matches then
		if script.Parent.CanUse.Value == true then
			script.Parent.RemoteEvent:FireServer(string.upper(Colourname),RGBColourPreview.BackgroundColor3)
			RGBColourName.TextColor3 = Color3.fromRGB(0,255,0)
			script.Success:Play()
			script.Parent.CanUse.Value = false
			Creatimer()
		else
			script.Error:Play()
			RGBColourName.TextColor3 = Color3.fromRGB(255,0,0)
			RGBColourName.Text = "Kullanma hakkın yok."
			task.wait(2)
			RGBColourName.TextColor3 = Color3.fromRGB(255,255,255)
			RGBColourName.Text = "RGB değerleri"
		end
	else
		script.Error:Play()
		RGBColourName.TextColor3 = Color3.fromRGB(255,0,0)
		RGBColourName.Text = "Renk geçerli değil."
		task.wait(2)
		RGBColourName.TextColor3 = Color3.fromRGB(255,255,255)
		RGBColourName.Text = "RGB değerleri"
	end
end)

ColourBox.FocusLost:Connect(function()
	if Colors[string.lower(ColourBox.Text)] then
		if script.Parent.CanUse.Value == true then
			script.Parent.RemoteEvent:FireServer(string.upper(ColourBox.Text),Colors[string.lower(ColourBox.Text)])
			ColourBox.TextColor3 = Color3.fromRGB(0,255,0)
			ColourBox.UIStroke.Color = Color3.fromRGB(0,255,0)
			script.Success:Play()
			script.Parent.CanUse.Value = false
			Creatimer()
		else
			script.Error:Play()
			ColourBox.TextEditable = false
			ColourBox.TextColor3 = Color3.fromRGB(255,0,0)
			ColourBox.UIStroke.Color = Color3.fromRGB(255,0,0)
			ColourBox.Text = "Kullanma hakkın yok."
			task.wait(2)
			ColourBox.TextEditable = true
			ColourBox.TextColor3 = Color3.fromRGB(255,255,255)
			ColourBox.UIStroke.Color = Color3.fromRGB(255,255,255)
			ColourBox.Text = ""
		end
	else
		script.Error:Play()
		ColourBox.TextEditable = false
		ColourBox.TextColor3 = Color3.fromRGB(255,0,0)
		ColourBox.UIStroke.Color = Color3.fromRGB(255,0,0)
		ColourBox.Text = "Renk geçerli değil."
		task.wait(2)
		ColourBox.TextEditable = true
		ColourBox.TextColor3 = Color3.fromRGB(255,255,255)
		ColourBox.UIStroke.Color = Color3.fromRGB(255,255,255)
		ColourBox.Text = ""
	end
end)

started when i added the

GreenColourBox.Text = string.gsub(GreenColourBox.Text,"%p","")

lines

heared debug for first time.what does it do? can you send an documentation?

GreenColourBox:GetPropertyChangedSignal("Text"):Connect(function()
    script.Typewriter:Play()
    GreenColourBox.Text = string.gsub(GreenColourBox.Text, "%a", "") -- Remove letters
    GreenColourBox.Text = string.gsub(GreenColourBox.Text, "%p", "") -- Remove punctuation
    -- Ensure the text is numeric and within range, defaulting to "0" if not
    local numericValue = tonumber(GreenColourBox.Text) or 0
    numericValue = math.max(0, math.min(255, numericValue)) -- Clamp value between 0 and 255
    GreenColourBox.Text = tostring(numericValue)
    GreenColourPreview.BackgroundColor3 = Color3.fromRGB(0, numericValue, 0)
    RGBColourPreview.BackgroundColor3 = Color3.new(RedColourPreview.BackgroundColor3.R, GreenColourPreview.BackgroundColor3.G, BlueColourPreview.BackgroundColor3.B)
end)

Make similar adjustments for the RedColourBox and BlueColourBox to ensure consistent and correct behavior across all inputs.

why didnt i thinked that…

also could math.clamp work? but i think your opinion is the best.

That could even be a better choice

GreenColourBox:GetPropertyChangedSignal("Text"):Connect(function()
    script.Typewriter:Play()
    GreenColourBox.Text = string.gsub(GreenColourBox.Text, "%a", "") -- Remove letters
    GreenColourBox.Text = string.gsub(GreenColourBox.Text, "%p", "") -- Remove punctuation
    -- Ensure the text is numeric
    local numericValue = tonumber(GreenColourBox.Text) or 0
    -- Clamp the value to ensure it's between 0 and 255
    numericValue = math.clamp(numericValue, 0, 255)
    GreenColourBox.Text = tostring(numericValue)
    GreenColourPreview.BackgroundColor3 = Color3.fromRGB(0, numericValue, 0)
    RGBColourPreview.BackgroundColor3 = Color3.new(RedColourPreview.BackgroundColor3.R, GreenColourPreview.BackgroundColor3.G, BlueColourPreview.BackgroundColor3.B)
end)

i learned the issue i think its because this line:

GreenColourBox.Text = string.gsub(GreenColourBox.Text,"","0")

but now your opinion made my rgb colour boxes have an inf number.

no no no it fixed my issue it was because something not completed.i completed it and now works fine.without crashing thank you :slight_smile:

your reward: a meme


next time,i will do this when i needed.

1 Like

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