So I was trying to create a script that checks the classname of the instance in an array and then prints it out. It does not work. I tried searching about this online with people who have had the same problem but all there scripts there where to complex. Can you please tell me am I doing wrong?
Error:
ServerScriptService.Script:6: attempt to concatenate string with Instance
Script:
local Food = game.Workspace.Food
local array = {Food, 5.4352, game.Workspace.ColorLooping.Parent}
local Value = array[1]
if Value.ClassName == "Part" then
print("Value's Classname is "Part"")
end
You have to get the Instance’s name using .Name
to concatenate it. You must also use the ..
to combine it.
print("Value's Classname is "..Value.Name)
Like this?
local Food = game.Workspace.Food
local array = {Food, 5.4352, game.Workspace.ColorLooping.Parent}
local Value = array[1]
if Value.Name == "Part" then
print("Value's Classname is " .. Value)
end
In the print statement, it has to use the string version of the Value. The string version is Value.Name
.
Sorry, I got confused. You meant like this right?
local Food = game.Workspace.Food
local array = {Food, 5.4352, game.Workspace.ColorLooping.Parent}
local Value = array[1]
if Value.ClassName == "Part" then
print("Value's Classname is " .. Value.Name)
end
Yes that is what I meant. It should work, under the assumption that “Food” is a Part.
I made so adjustments and how can I print the Value.Name in quotations?
local Food = game.Workspace.Food
local array = {Food, 5.4352, game.Workspace.ColorLooping.Parent}
local Value = array[1]
if Value.ClassName == "Part" then
print("Value's " .. Value.Name .. " Classname is " .. "Part")
end
It just turns the Value.Name into a string if I put quotations…
I want the output to be:
Value’s “Food” Classname is Part
Just do this then I guess
MrFlawless
VakarisLDoE
Programmer
Tyler
1m
I made so adjustments and how can I print the Value.Name in quotations?
local Food = game.Workspace.Food
local array = {Food, 5.4352, game.Workspace.ColorLooping.Parent}
local Value = array[1]
if Value.ClassName == "Part" then
print("Value's '" .. Value.Name .. "' Classname is " .. "Part")
end
Thanks for that! Appreciate for the help!
1 Like