Attempt to index nil with 'IsA

for _, v in pairs(workspace:GetDescendants()) do
	if v:IsA("Texture") and v.Texture == "http://www.roblox.com/asset/?id=321324778" and v.Parent:IsA("BasePart") and v.Parent.Parent:FindFirstChild("NewBed2") then
		v.Parent.Parent.PrimaryPart = v.Parent
		v.Parent.Name = "PrimaryPart"
		
		local Values = game.ServerStorage.Values:Clone()
		Values.Parent = v.Parent.Parent
		
		local RegionPart = Instance.new("Part")
		RegionPart.Name = "RegionPunkt"
		RegionPart.Anchored = true
		RegionPart.CanCollide = false
		RegionPart.Transparency = 1
		RegionPart.Parent = v.Parent.Parent.Values
		RegionPart.Size = Vector3.new(1,1,1)
		RegionPart.Position = v.Parent.Position + Vector3.new(0,7.5,0)
		RegionPart.Size = Vector3.new(25.4, 15, 37)
		
		v.Parent.Parent:SetAttribute("Division", "")
		
		print("lol")
	end
	
	if v.Name == "Lampen" then
		v:Destroy()
	end
	
	if v:FindFirstChild("HaufenLinks") then
		v:Destroy()
	end
	
	if v.Name == "Stuhl" then
		v:Destroy()
	end
	
	if string.sub(v.Name,1,6) == "NewBed" then
		v:Destroy()
	end
	
	if v:FindFirstChild("NewSteckdose") then
		v.Parent:Destroy()
	end
end

That’s a script to setup somethings in my Buildings. The problem is that I always get the error “for _, v in pairs(workspace:GetDescendants()) do
if v:IsA(“Texture”) and v.Texture == “http://www.roblox.com/asset/?id=321324778” and v.Parent:IsA(“BasePart”) and v.Parent.Parent:FindFirstChild(“NewBed2”) then
v.Parent.Parent.PrimaryPart = v.Parent
v:2: attempt to index nil with 'IsA”. I don’t know how to fix it. Thx for help.

It means that the variable “v” is nil, or in other words, does not exist. The script is running before the game is loaded, that’s what’s most likely happening. Try adding a wait(2) at the top of the script, although I’m sure there is a better way but I need to check.

you can try something like:

if v and v:IsA("Texture") then 
   --do stuff
end