ObjectValue value not changing

Hello! I have made a flower-generating script. After the flower is generated there is an ObjectValue inside of it whose value is supposed to be set to the tile the flower was generated.
I have tried browsing through the Developer Forum but I haven’t been able to find a solution for this.

Here is the code:

local tiles = greenHouse:GetChildren()
local chosenTile = tiles[math.random(1,#tiles)]
		if chosenTile:IsA("Part") and chosenTile.Taken.Value == false then
			chosenTile.Taken.Value = true 
			local playerSeeds = seeds:GetChildren()
			local seed = playerSeeds[math.random(1,#playerSeeds)]
			local seedVal = seed.Value
			if seedVal > 0 then
				local isFlower = plantModule["Biomes"][seed.Biome.Value][seed.Name]
				if isFlower ~= nil then 
					local newFlower = isFlower[2]:Clone()
						newFlower.Parent = workspace
						newFlower:SetPrimaryPartCFrame(chosenTile.CFrame)
						chosenTile.Taken.Value = true
						local tile = Instance.new("ObjectValue", newFlower)
						tile.Value = chosenTile -- **Here is where the value is supposed to be changed**
						tile.Name = "Tile"
						seed.Value -= 1
						for _, v in pairs(newFlower:GetDescendants()) do
								if v:IsA("Part") or v:IsA("MeshPart") then
									v.Position = v.Position - Vector3.new(0,10,0)					
								end
						end
						for _, v in pairs(newFlower:GetDescendants()) do
								if v:IsA("Part") or v:IsA("MeshPart") then
									game.TweenService:Create(v, tweeninfo, {Position = v.Position + Vector3.new(0,13,0)}):Play()		
								end
						end	
				end
		end
end

Thank you in advance,
Sxr1pted

Avoid using the second argument of Instance.new() to set the parent of the object, the reason for that is that you should avoid parenting anything before setting its properties, such as Value, Name or other properties.

So in your case, you’ll instantiate the ObjectValue, set its Value & Name, then parent it to newFlower.

local tile = Instance.new("ObjectValue")
tile.Value = chosenTile
tile.Name = "Tile"
tile.Parent = newFlower
1 Like

Try changing the ObjectValue to a different type of value, like a StringValue and see if that does change anything, because Object only works on one object, not a whole model.
If it is indeed a model then try simplifying exactly what inside the model, should the object value be looking for


tile.Value = chosenTile.(The specific part that you want)


hope this helps. If it doesn’t then oh well I tried :…]

The chosen tile is a part randomly picked from a folder. But thank you!