Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Unable to cast value to std::string error?

This script is suppost to change a surface Gui background color but it doesn't and outputs out Unable to cast value to std::string Could anyone possibly fix this?


function Pad(name,color)
	return script.Parent.Pads:FindFirstChild(name).BackgroundColor3 == color
end

local LetterTable = {
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
}

function Spread(color)
	local number = math.random(1, 10)
	Pads("A"..number, color)
	Pads("B"..number, color)
	Pads("C"..number, color)
	Pads("D"..number, color)
	Pads("E"..number, color)
	Pads("F"..number, color)
	Pads("G"..number, color)
	Pads("H"..number, color)
	Pads("I"..number, color)
	Pads("J"..number, color)
end

while true do
	wait(0.5)
	Spread(Color.new(255, 0, 0))
end


6 comments

0

Color.new does not accept an RGB value from 0 to 255, instead, 0 to 1. To use a RGB value, you should use Color.fromRGB()

0

Still not working

0

It's something with Line 2

0

It's something with Line 2

0

Try use printing and see what works and what dosen't

0

You are using return in a function and never seeing what the function returns???

1 answer

✓ Accepted answer

A couple of problems.


Firstly, you are trying to use Color3.new with numbers 0-255. Color3.new only takes values from 0-1, so if you want to use 255, you can do one of the following:

Color3.new(255/255,0,0) -->> Divide all values by 255
Color3.fromRGB(255,0,0) -->> Use fromRGB

-->> Equivalent to 1,0,0

Otherwise you could just do:

Color3.new(1,0,0)

Secondly, you are trying to set a value while returning it. Simple fix, don't return. You don't even have a reason to use it in this context.

-->> This will work

function Func()
	Variable = Value
end
-->> This won't work

function Func()
	return Variable = Value
end

Hope I helped!

~TDP

This discussion is preserved as it was. New answers, comments, and votes are closed.