Attempt to concatenate string with nil

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Make it so it doesn’t give me a script error when I do “!crownhouse whateverherebanner”
  2. What is the issue? Include screenshots / videos if possible!
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Nothing so far, because it doesn’t show any warnings or errors for the script:

local PO = workspace.Mechanics
local Banners = PO.Banners
local RS = game:GetService("ReplicatedStorage")
local Modules = RS:WaitForChild("Modules")
local HouseModule = require(Modules:WaitForChild("Houses"))
local List = HouseModule.List

local HouseName = game.ReplicatedStorage:WaitForChild("Values"):WaitForChild("HouseName")
HouseName.Value = game:GetService("HttpService"):GetAsync("https://pastebin.com/raw/jbsiamGe")
wait(1)

function findData(HouseName,DataToFind)
	for i,v in pairs(List) do
		if v["Name"] == HouseName then
			if v[DataToFind] then
				return v[DataToFind]
			end
		end
	end
end

function ChangeBanners()
	for i,v in pairs(Banners:GetChildren())do
		if v.Name == "Banner" and v:FindFirstChild("Sigil") then
			if v.Sigil:FindFirstChild("Decal") then
				v.Sigil.Decal.Texture = "rbxassetid://"..findData(HouseName.Value,"Sigil")
			end
		
			for i,v in pairs(v:GetChildren())do
				if v:IsA("BasePart") and v.Name ~= "Wooden" and v.Name ~= "Sigil" then
					v.BrickColor = findData(HouseName.Value,"Color")
				end
			end
		end
	end
end

HouseName.Changed:connect(function()
	ChangeBanners()
end)

ChangeBanners()

game.Players.PlayerAdded:connect(function(Player)
	Player.Chatted:connect(function(Message)
		if Player.Name == "49dec" or Player.Name == "player1" then
			if string.sub(Message,1,12) == "!crownhouse " then
				HouseName.Value = string.sub(Message,13,string.len(Message))
			elseif string.lower(Message) == "!updatebanners" then
				HouseName.Value = game:GetService("HttpService"):GetAsync("https://pastebin.com/raw/4fzhDzGS")	
			end
		end
	end)
end)

Script ^

3 Likes

I’m assuming this is the line throwing the error:

v.Sigil.Decal.Texture = "rbxassetid://"..findData(HouseName.Value,"Sigil")

So the problem is that your findData function can potentially return “nil”

What you could do is check that findData returned valid data before attempting to change the texture:

function ChangeBanners()
	local sigil = findData(HouseName.Value,"Sigil")
	local color = findData(HouseName.Value,"Color")
	if (sigil ~= nil and color ~= nil) then
		for i,v in pairs(Banners:GetChildren())do
			if v.Name == "Banner" and v:FindFirstChild("Sigil") then
				if v.Sigil:FindFirstChild("Decal") then
					v.Sigil.Decal.Texture = "rbxassetid://"..sigil
				end
			
				for i,v in pairs(v:GetChildren())do
					if v:IsA("BasePart") and v.Name ~= "Wooden" and v.Name ~= "Sigil" then
						v.BrickColor = color
					end
				end
			end
		end
	else
		warn("House name not recognized.")
	end
end
8 Likes